Skip to content

Optimize type variable scope map cloning with CoW#3573

Open
jakebailey wants to merge 2 commits intomainfrom
jabaile/type-var-optim
Open

Optimize type variable scope map cloning with CoW#3573
jakebailey wants to merge 2 commits intomainfrom
jabaile/type-var-optim

Conversation

@jakebailey
Copy link
Copy Markdown
Member

This restores the copy-on-write in the original Strada code, which saves the creation of new maps. On the testrunner test suite, this saves about 720k allocations.

Copilot AI review requested due to automatic review settings April 24, 2026 05:01
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 restores a copy-on-write approach for NodeBuilderContext’s per-signature scope maps to reduce allocations when cloning scope state during type serialization.

Changes:

  • Added core.CloneOrMakeMap utility to clone an existing map or allocate an empty one when nil.
  • Updated cloneNodeBuilderContext to share inherited maps and defer cloning until mutation is required.
  • Updated node builder mutation sites to clone-on-first-write using core.CloneOrMakeMap.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/core/core.go Adds CloneOrMakeMap helper to support clone-on-write map patterns.
internal/checker/nodebuilderscopes.go Switches scope cloning from eager map cloning to CoW by resetting “created” flags while sharing maps.
internal/checker/nodebuilderimpl.go Clones the shared maps on first mutation using core.CloneOrMakeMap instead of allocating fresh empty maps.

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