-
Notifications
You must be signed in to change notification settings - Fork 832
Closed
Labels
Area-LibraryIssues for FSharp.Core not covered elsewhereIssues for FSharp.Core not covered elsewhereFeature Requestgood first issuehelp wanted
Milestone
Description
There are some dynamic type checks here and there in FSharp.Core that all use Type.Equals instead of Type.op_Equality. Only the latter is optimized by the JIT for branch elimination (reference vs value type) and lookup table transformation for shared reference type checks. That's some easy free perf on the generic equality.
fsharp/src/fsharp/FSharp.Core/prim-types.fs
Lines 2341 to 2357 in db2ba9e
| type GenericZeroDynamicImplTable<'T>() = | |
| static let result : 'T = | |
| // The dynamic implementation | |
| let aty = typeof<'T> | |
| if aty.Equals(typeof<sbyte>) then unboxPrim<'T> (box 0y) | |
| elif aty.Equals(typeof<int16>) then unboxPrim<'T> (box 0s) | |
| elif aty.Equals(typeof<int32>) then unboxPrim<'T> (box 0) | |
| elif aty.Equals(typeof<int64>) then unboxPrim<'T> (box 0L) | |
| elif aty.Equals(typeof<nativeint>) then unboxPrim<'T> (box 0n) | |
| elif aty.Equals(typeof<byte>) then unboxPrim<'T> (box 0uy) | |
| elif aty.Equals(typeof<uint16>) then unboxPrim<'T> (box 0us) | |
| elif aty.Equals(typeof<uint32>) then unboxPrim<'T> (box 0u) | |
| elif aty.Equals(typeof<uint64>) then unboxPrim<'T> (box 0UL) | |
| elif aty.Equals(typeof<unativeint>) then unboxPrim<'T> (box 0un) | |
| elif aty.Equals(typeof<decimal>) then unboxPrim<'T> (box 0M) | |
| elif aty.Equals(typeof<float>) then unboxPrim<'T> (box 0.0) | |
| elif aty.Equals(typeof<float32>) then unboxPrim<'T> (box 0.0f) |
Ideally I'd like to see a static optimization for (=) (x:Type, y:Type) to use Type.op_Equality @dsyme is this something you're ok with?
abelbraaksma and rstm-sf
Metadata
Metadata
Assignees
Labels
Area-LibraryIssues for FSharp.Core not covered elsewhereIssues for FSharp.Core not covered elsewhereFeature Requestgood first issuehelp wanted
Type
Projects
Status
Done