-
Notifications
You must be signed in to change notification settings - Fork 718
Pool EmitContext #1287
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
Pool EmitContext #1287
Conversation
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 introduces pooling for EmitContext
instances to reduce allocations by reusing contexts across files. Key changes include:
- Added
sync.Pool
andGetEmitContext
/release functions ininternal/printer/emitcontext.go
. - Updated consumers (
emitter.go
and test baselines) to useGetEmitContext
with deferred release instead ofNewEmitContext
. - Ensured
EmitContext.Reset()
clears prior state before returning to the pool.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
internal/testutil/tsbaseline/type_symbol_baseline.go | Switched from NewEmitContext() to pooled GetEmitContext() /putCtx() . |
internal/printer/emitcontext.go | Introduced sync.Pool , GetEmitContext + release func, and Reset() . |
internal/compiler/emitter.go | Replaced NewEmitContext() with GetEmitContext() and deferred release. |
Comments suppressed due to low confidence (2)
internal/compiler/emitter.go:136
- [nitpick] Consider standardizing the name of the cleanup function returned by
GetEmitContext()
(e.g.putCtx
orreleaseCtx
) across the codebase to avoid confusion when reading pooled-context usage.
emitContext, putEmitContext := printer.GetEmitContext()
internal/printer/emitcontext.go:47
- Add a unit test to verify that an
EmitContext
obtained viaGetEmitContext()
is reset to a clean state after calling the release function, ensuring no leftover state persists between uses.
func GetEmitContext() (*EmitContext, func()) {
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.
Probably a good idea - any before/after numbers?
For the test runner, it accounts for 5% of the allocations (6179460), and with this PR just 0.1% (99838). |
* Update submodule, fix JSON syntax problems (microsoft#1285) * Pool EmitContext (microsoft#1287) --------- Co-authored-by: Jake Bailey <[email protected]>
* Update submodule, fix JSON syntax problems (microsoft#1285) * Pool EmitContext (microsoft#1287) --------- Co-authored-by: Jake Bailey <[email protected]>
* Update submodule, fix JSON syntax problems (microsoft#1285) * Pool EmitContext (microsoft#1287) --------- Co-authored-by: Jake Bailey <[email protected]>
* Update submodule, fix JSON syntax problems (microsoft#1285) * Pool EmitContext (microsoft#1287) --------- Co-authored-by: Jake Bailey <[email protected]>
* Update submodule, fix JSON syntax problems (microsoft#1285) * Pool EmitContext (microsoft#1287) --------- Co-authored-by: Jake Bailey <[email protected]>
These objects can be reused, which is good because we create one of them per file to emit.