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:
SirOlaf
2026-08-10 10:18:15 +02:00
committed by GitHub
parent 708d9311e8
commit 2d22f24359
3 changed files with 69 additions and 6 deletions

View File

@@ -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.