Enum type as field value performance

HashBrown
Mon, 17 Oct 2022 19:34:12 +0000
General Usage

I know it is discouraged to use an abstract type for a field in a composite type due to the runtime overhead of looking up the type and method resolution.

Does using an enum type suffer from the same problem? Or is it more performant.

Example:

abstract type Side end
struct Bid <: Side end
struct Ask <: Side end

struct Trade
    ...
    s::Side
end

vs

@enum Side bid ask

struct Trade
    ...
    s::Side
end

Note: in the first code snippet I know I could use a type parameter, but that would lead to type instabilities elsewhere for me

2 posts - 2 participants