Skip to content

perf(ast/estree): faster serializing strings to JSON #11753

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

Merged

Conversation

overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Jun 16, 2025

Speed up serializing strings to JSON, using a trick I found in Chromium's code, to check a batch of 8 bytes in one go for characters needing escaping, rather than checking bytes 1 by 1.

https://chromium.googlesource.com/v8/v8/+/1645281bbd1b183a252835d376166bd210135bbe/src/json/json-stringifier.cc#521

@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Jun 16, 2025
Copy link
Contributor Author

overlookmotel commented Jun 16, 2025


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.

Copy link

codspeed-hq bot commented Jun 16, 2025

CodSpeed Instrumentation Performance Report

Merging #11753 will degrade performances by 13.11%

Comparing 06-16-perf_ast_estree_faster_serializing_strings_to_json (c4faee2) with main (2641030)

Summary

❌ 1 regressions
✅ 37 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
mangler[cal.com.tsx] 3.1 ms 3.5 ms -13.11%

@overlookmotel overlookmotel marked this pull request as ready for review June 16, 2025 18:48
@overlookmotel overlookmotel force-pushed the 06-16-perf_ast_estree_faster_serializing_strings_to_json branch from a055e05 to 7753796 Compare June 16, 2025 18:53
@overlookmotel overlookmotel marked this pull request as draft June 16, 2025 18:57
@overlookmotel overlookmotel marked this pull request as draft June 16, 2025 18:57
@overlookmotel overlookmotel marked this pull request as ready for review June 16, 2025 19:16
@overlookmotel
Copy link
Contributor Author

overlookmotel commented Jun 16, 2025

1% perf improvement on ESTree benchmark. Would probably show a larger effect on a file which is string-heavy e.g. RadixUI benchmark.

@overlookmotel overlookmotel force-pushed the 06-16-perf_ast_estree_faster_serializing_strings_to_json branch from 1ebaf29 to f953447 Compare June 16, 2025 21:44
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Jun 17, 2025
Copy link
Contributor

graphite-app bot commented Jun 17, 2025

Merge activity

Speed up serializing strings to JSON, using a trick I found in Chromium's code, to check a batch of 8 bytes in one go for characters needing escaping, rather than checking bytes 1 by 1.

https://chromium.googlesource.com/v8/v8/+/1645281bbd1b183a252835d376166bd210135bbe/src/json/json-stringifier.cc#521
@graphite-app graphite-app bot force-pushed the 06-16-perf_ast_estree_faster_serializing_strings_to_json branch from f953447 to c4faee2 Compare June 17, 2025 02:07
@graphite-app graphite-app bot merged commit c4faee2 into main Jun 17, 2025
24 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jun 17, 2025
@graphite-app graphite-app bot deleted the 06-16-perf_ast_estree_faster_serializing_strings_to_json branch June 17, 2025 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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