Skip to content

Use @streamparser/json if the input is too large to fit in a V8 string#6016

Open
mstange wants to merge 1 commit into
firefox-devtools:mainfrom
mstange:jsonstreamparser
Open

Use @streamparser/json if the input is too large to fit in a V8 string#6016
mstange wants to merge 1 commit into
firefox-devtools:mainfrom
mstange:jsonstreamparser

Conversation

@mstange
Copy link
Copy Markdown
Contributor

@mstange mstange commented May 11, 2026

Here's a file which decompresses to a 605.8MB JSON string: etw-speedometer3.json.gz

Loading this file in Chrome, or in node via profiler-edit, fails due to the string size.

As a workaround we can use a streaming JSON parser which doesn't materialize a string for the entire thing.

@mstange mstange requested review from canova and fatadel as code owners May 11, 2026 20:55
@mstange mstange force-pushed the jsonstreamparser branch from 8f4934a to 566cf0f Compare May 11, 2026 21:23
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

❌ Patch coverage is 63.63636% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.80%. Comparing base (642c1fd) to head (566cf0f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/profile-logic/process-profile.ts 63.63% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6016      +/-   ##
==========================================
- Coverage   83.82%   83.80%   -0.02%     
==========================================
  Files         328      328              
  Lines       34255    34283      +28     
  Branches     9572     9581       +9     
==========================================
+ Hits        28713    28731      +18     
- Misses       5114     5124      +10     
  Partials      428      428              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@fatadel fatadel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me personally, but Claude found a minor issue:

V8_STRING_MAX_SIZE is slightly above the actual V8 limit. The constant is 512 * 1024 * 1024 - 1 = (1 << 29) - 1 = 536870911. V8's String::kMaxLength under pointer compression (the typical config — buffer.constants.MAX_STRING_LENGTH exposes this in Node) is (1 << 29) - 24 = 536870888. That leaves a ~23-byte window where the size check passes but the ASCII-decoded string would still throw RangeError: Invalid string length. Practically irrelevant, but the fix is trivial: (1 << 29) - 24, or just import buffer.constants.MAX_STRING_LENGTH in Node paths.

@mstange
Copy link
Copy Markdown
Contributor Author

mstange commented May 13, 2026

Hah, oops.

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