Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

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

Merged
Wesley Wigham (weswigham) merged 5 commits into
microsoft:mainfrom
weswigham:arena-resets-test
Jun 8, 2026
Merged

Wesley Wigham (weswigham) merged 5 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 Resolved
Comment thread internal/checker/printer.go Resolved
Comment thread internal/checker/printer.go Resolved
Comment thread internal/ast/ast_generated.go Outdated
}

func (f *NodeFactory) ReleaseArenas() {
f.arrayTypeNodeArena.Release()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it easier to just have this do *f = NodeFactory{...}, copying in what to save?

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.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mainly I say this because it's many calls versus a single memzero + memcopy

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.

Alright, swapped to that.

@weswigham
Wesley Wigham (weswigham) added this pull request to the merge queue Jun 8, 2026
Merged via the queue into microsoft:main with commit e90bfe2 Jun 8, 2026
21 checks passed
@weswigham
Wesley Wigham (weswigham) deleted the arena-resets-test branch June 8, 2026 18:23
Jake Bailey (jakebailey) pushed a commit to jakebailey/TypeScript that referenced this pull request Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants