Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cartermp opened this issue Jan 11, 2019 · 0 comments

Comments

@cartermp
Copy link
Contributor

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?

@dsyme dsyme added the bug label Mar 20, 2019
@dsyme dsyme added enhancement and removed bug labels Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants