Compiler eagerly imports IL type defs from unopened namespaces consisting of a single name #16166
Labels
Area-Compiler-Optimization
The F# optimizer, release code gen etc.
Bug
Impact-Medium
(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone
When the compiler reads IL metadata, it reads type defs lazily, so types aren't read and kept in memory unless they are referenced somewhere or their containing namespace is imported. Instead of immediately importing types, special placeholders (
ILPreTypeDef
) are created.It turns out that if a namespace consist of a single name, then this optimization isn't applied, and its types are eagerly imported. Moreover, this happens during a background builder creation, before any file in a project is analyzed.
This should affect the startup time and memory consumption of the compiler.
I've tested it on a referenced assembly with a single type
T
, and it depends on theT
namespace:Ns.T
is imported eagerlyNs1.Ns2.T
is not importedThe following source code was used in the tests, no namespaces were imported:
Here's a screenshot of the stack trace from the test with
Ns.T
type:This problem reproduces for other types, so types from namespaces like
System
are always imported on startup:The text was updated successfully, but these errors were encountered: