Skip to content

Allow nil-ing out arenas to break the GC link between nodes and the arena they came from#4024

Open
weswigham wants to merge 2 commits into
microsoft:mainfrom
weswigham:arena-resets-test
Open

Allow nil-ing out arenas to break the GC link between nodes and the arena they came from#4024
weswigham wants to merge 2 commits into
microsoft:mainfrom
weswigham:arena-resets-test

Conversation

@weswigham
Copy link
Copy Markdown
Member

Which should lower the average retained memory total of diagnostic generation.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 new release callback returned from Checker.getNodeBuilder().
  • Update various Checker stringification/printing helpers to defer release() after using the shared cached NodeBuilder.

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

Comment thread internal/core/arena.go
return slice
}

// Reset arena back to zero, removing GC refs between the arena and any objects in the arena, allowing them to be freed
Comment on lines 202 to 204
if vc != nil {
nodeBuilder.verbosity = vc
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabritto @RyanCavanaugh I'm pretty sure this copilot comment just picked up on the fix for #4010 (unrelated to this PR though)

Comment on lines 326 to 328
if vc != nil {
nodeBuilder.verbosity = vc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants