mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-26 00:21:42 +00:00
Same-module generic cache for lazy instantiation (#26091)
We defer copying the AST during generic instantiation until a cache miss and fetch from cache based on bindings. On miss, we fall back to the old logic and populate the cache. This gains us a roughly 36% reduction in memory usage during bootstrap, from `799.242MiB` down to `508.672MiB` on my machine. For another point of reference, nimbus-eth2 goes from `10.5GB` memory usage to `7.5GB`. Independent companion to #26090 which together with this one yields a bit under 20% faster compiles (or at least `--compileOnly` bootstraps) on ORC.
This commit is contained in:
@@ -681,6 +681,10 @@ type
|
||||
TInstantiation* = object
|
||||
sym*: PSym
|
||||
concreteTypes*: seq[PType]
|
||||
bindings*: seq[tuple[key: ItemId, value: PType]]
|
||||
## An optional exact snapshot of the matcher bindings. In-process
|
||||
## instances use it for a fast cache probe; serialized instances fall
|
||||
## back to comparing the fully instantiated signature.
|
||||
genericParamsCount*: int # for terrible reasons `concreteTypes` contains all the types,
|
||||
# so we need to know how many generic params there were
|
||||
# this is not serialized for IC and that is fine.
|
||||
|
||||
Reference in New Issue
Block a user