Skip to content
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

perf(ast/estree): pre-allocate CodeBuffer for JSON output #9340

Open
wants to merge 1 commit into
base: 02-23-perf_ast_estree_estree_serializer_use_codebuffer_
Choose a base branch
from

Conversation

overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Feb 24, 2025

ESTree serialization pre-allocate capacity in CodeBuffer for JSON, based on an heuristic ratio of source text length to JSON length, to avoid the buffer having to grow during serialization.

Copy link
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@overlookmotel overlookmotel marked this pull request as ready for review February 24, 2025 18:27
@overlookmotel overlookmotel marked this pull request as draft February 24, 2025 18:28
Copy link

codspeed-hq bot commented Feb 24, 2025

CodSpeed Performance Report

Merging #9340 will improve performances by 24.38%

Comparing 02-24-perf_ast_estree_pre-allocate_codebuffer_for_json_output (b179153) with 02-23-perf_ast_estree_estree_serializer_use_codebuffer_ (2c8281a)

Summary

⚡ 1 improvements
✅ 32 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
estree[checker.ts] 152 ms 122.2 ms +24.38%

@overlookmotel
Copy link
Contributor Author

overlookmotel commented Feb 24, 2025

Now we're talking!

To be fair, this effect is only so pronounced because the file we're benchmarking - checker.ts - is so large that it generates about 3 MB of JSON. If the buffer has to grow, copying a chunk of memory that large is really expensive. The effect would be much smaller on average size files.

@overlookmotel overlookmotel marked this pull request as ready for review February 24, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ast Area - AST C-performance Category - Solution not expected to change functional behavior, only performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant