Repository navigation
Allow nil-ing out arenas to break the GC link between nodes and the arena they came from - #4024
Conversation
…rena they came from
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce retained memory during diagnostic/type rendering by explicitly releasing AST node allocation arenas after short-lived node-building operations, breaking GC retention between the cached NodeBuilder/EmitContext and previously allocated nodes.
Changes:
- Add
Arena.Release()to nil out arena backing slices and allow GC to reclaim unused allocations. - Generate
(*ast.NodeFactory).ReleaseArenas()and invoke it via a newreleasecallback returned fromChecker.getNodeBuilder(). - Update various
Checkerstringification/printing helpers todefer release()after using the shared cachedNodeBuilder.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/core/arena.go | Adds Arena.Release() to drop references to arena backing storage. |
| internal/checker/printer.go | Uses getNodeBuilder() release callback in type/symbol/signature stringification paths. |
| internal/checker/nodebuilder.go | Changes getNodeBuilder() to return (builder, release) and releases node factory arenas after use. |
| internal/ast/ast_generated.go | Adds generated NodeFactory.ReleaseArenas() that releases all node arenas. |
| _scripts/generate-go-ast.ts | Updates generator to emit ReleaseArenas() for NodeFactory. |
Files not reviewed (1)
- internal/ast/ast_generated.go: Language not supported
| } | ||
|
|
||
| func (f *NodeFactory) ReleaseArenas() { | ||
| f.arrayTypeNodeArena.Release() |
There was a problem hiding this comment.
Is it easier to just have this do *f = NodeFactory{...}, copying in what to save?
There was a problem hiding this comment.
Eh... I think the layering and embedding of node factories make the explicitness here a bit nicer, since it allows overriding on a factory subtype if it, eg, adds more arenas, but yeah, we could just copy hooks/nodecount/textcount and zero the rest.
There was a problem hiding this comment.
Mainly I say this because it's many calls versus a single memzero + memcopy
There was a problem hiding this comment.
Alright, swapped to that.
Which should lower the average retained memory total of diagnostic generation.