Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
Loading
from

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Jun 25, 2025

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.

@jakebailey jakebailey changed the title Clear node builder links when done Create a fresh NodeBuilder and EmitContext instead of caching in checker Jun 25, 2025
@jakebailey jakebailey changed the title Create a fresh NodeBuilder and EmitContext instead of caching in checker Avoid holding on to NodeBuilder in checker Jun 25, 2025
@jakebailey jakebailey requested a review from weswigham June 25, 2025 21:07
@jakebailey jakebailey marked this pull request as ready for review June 25, 2025 21:07
@Copilot Copilot AI review requested due to automatic review settings June 25, 2025 21:07
Copy link
Contributor

@Copilot 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 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 and c.diagnosticConstructionContext in printer.go with calls to c.getNodeBuilder() and its EmitContext().
  • Introduce Checker.getNodeBuilder() in nodebuilder.go to return either a cached builder (during checkSourceFile) or a new builder each time.
  • Remove diagnosticConstructionContext and nodeBuilder fields from Checker in checker.go, and instrument inCheckSourceFile 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.

@DanielRosenwasser
Copy link
Member

Somewhat related question - do node builders use pooled allocators the same way the parser does?

@jakebailey
Copy link
Member Author

Yes, they do.

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.