Skip to content

Determining FSharp.Core version allocates large arrays on the large object heap #287

Open
@cartermp

Description

@cartermp

From here: dotnet/fsharp#5930 (comment)

The following code ends up reading all of FSharp.Core.dll and one of mscorlib.dll/system.runtime.dll/netstandard.dll into byte arrays upon type provider instantiation:

let systemRuntimeScopeRef =
lazy
referencedAssemblyPaths |> List.tryPick (fun path ->
try
let simpleName = Path.GetFileNameWithoutExtension path
if simpleName = "mscorlib" || simpleName = "System.Runtime" || simpleName = "netstandard" then
let reader = ILModuleReaderAfterReadingAllBytes (path, mkILGlobals EcmaMscorlibScopeRef)
let mdef = reader.ILModuleDef
match mdef.TypeDefs.TryFindByName(USome "System", "Object") with
| None -> None
| Some _ ->
let m = mdef.ManifestOfAssembly
let assRef = ILAssemblyRef(m.Name, UNone, (match m.PublicKey with USome k -> USome (PublicKey.KeyAsToken(k)) | UNone -> UNone), m.Retargetable, m.Version, m.Locale)
Some (ILScopeRef.Assembly assRef)
else
None
with _ -> None )
|> function
| None -> EcmaMscorlibScopeRef // failwith "no reference to mscorlib.dll or System.Runtime.dll or netstandard.dll found"
| Some r -> r
let fsharpCoreRefVersion =
lazy
referencedAssemblyPaths |> List.tryPick (fun path ->
try
let simpleName = Path.GetFileNameWithoutExtension path
if simpleName = "FSharp.Core" then
let reader = ILModuleReaderAfterReadingAllBytes (path, mkILGlobals (systemRuntimeScopeRef.Force()))
match reader.ILModuleDef.Manifest with
| Some m -> match m.Version with USome v -> Some v | UNone -> None
| None -> None
else
None
with _ -> None )
|> function
| None -> typeof<int list>.Assembly.GetName().Version // failwith "no reference to FSharp.Core found"
| Some r -> r

This work is unnecessary because the F# compiler already knows this information. However, changing this would require work both in here and the compiler. Perhaps there's a cheaper way than allocating multiple MB on the LOH?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions