-
Notifications
You must be signed in to change notification settings - Fork 653
Avoid holding on to NodeBuilder in checker #1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 424e767.
There was a problem hiding this 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 refactors how NodeBuilder
and its emit context are managed by the Checker
to avoid retaining large AST nodes in long-lived builder instances. Instead of a single persistent builder, fresh instances are created on each use (with a cached builder only during a checkSourceFile
run), allowing unused nodes to be garbage‐collected and addressing the memory/performance issue reported in #988.
- Replace all uses of
c.nodeBuilder
andc.diagnosticConstructionContext
inprinter.go
with calls toc.getNodeBuilder()
and itsEmitContext()
. - Introduce
Checker.getNodeBuilder()
innodebuilder.go
to return either a cached builder (duringcheckSourceFile
) or a new builder each time. - Remove
diagnosticConstructionContext
andnodeBuilder
fields fromChecker
inchecker.go
, and instrumentinCheckSourceFile
to manage the builder cache lifecycle.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
internal/checker/printer.go | Swapped persistent builder/context for local getNodeBuilder() calls and updated printer creation. |
internal/checker/nodebuilder.go | Added Checker.getNodeBuilder() method that conditionally reuses or creates a NodeBuilder . |
internal/checker/checker.go | Removed old builder/context fields, added inCheckSourceFile flag and cache field, and updated lifecycle in checkSourceFile . |
Somewhat related question - do node builders use pooled allocators the same way the parser does? |
Yes, they do. |
Holding onto the builder, the emit context, and therefore NodeFactory, holds onto a load of old nodes permanently. Create these fresh each time and let them get GC'd rather than try and manually clear everything.
As an optimization, reuse the same builder while checking the same file.For a perf problem found in #988.