Skip to content

First typed array: Allow profile.shared.stackTable.frame to be an Int32Array#6087

Merged
mstange merged 7 commits into
firefox-devtools:mainfrom
mstange:first-typed-array
Jun 17, 2026
Merged

First typed array: Allow profile.shared.stackTable.frame to be an Int32Array#6087
mstange merged 7 commits into
firefox-devtools:mainfrom
mstange:first-typed-array

Conversation

@mstange

@mstange mstange commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Main branch (loading v60 JSLB profile) | Deploy preview (loading v65 JSLB profile)


This is the first typed array that we're supporting inside the profile format.

When a profile is saved in the JsonSlabs format, it will now have this column as a separate slab that doesn't require JSON parsing.

Profile compacting now always turns stackTable.frame into a typed array, even if that column was a regular JS array in the input profile.

We still allow a regular JSON array here, because profiles stored as JSON cannot contain typed arrays, and we want to use the same type definition for JSON and JSLB profiles.

Here's how this change impacts profile sizes and loading times on this profile: https://storage.googleapis.com/profiler-get-symbols-fixtures/large-speedometer3-profile.json.gz (with this corresponding size profile)

Version .jslb.gz size .jslb size Load time Profile of it loading
64 122 MB 605 MB 7.6 seconds https://share.firefox.dev/4ogUKba
65 125 MB 544 MB 6.0 seconds https://share.firefox.dev/3Qopiem

The compressed size has grown a small bit, but the other savings are significant:

  • We no longer have 131 MB of text for the frame column in the JSON - the frame column is now stored in a 70 MB i32 slab.
  • Less time in GZ decompression, because the uncompressed size is now smaller.
  • There is a lot less time spent in TextDecoder.decode and JSON.parse, because we're no longer decoding and parsing 131 MB of text for the frame column.

@mstange mstange requested a review from canova June 4, 2026 18:42
@mstange mstange force-pushed the first-typed-array branch from 46dde73 to 0002a8e Compare June 4, 2026 18:44
This doesn't change anything about the profile format, this
is just about the derived in-memory representation.
@mstange mstange force-pushed the first-typed-array branch from 0002a8e to e7d0b56 Compare June 4, 2026 18:45
mstange added 4 commits June 4, 2026 14:47
`JSON.stringify` serializes typed arrays as objects with stringified
numeric keys (e.g. `{"0": 1, "1": 2}`), which is not what we want
when a profile contains typed arrays.

`jsonEncodeObjectWithTypedArraysAsRegularArrays` traverses the object
and converts any typed array it finds to a regular array of numbers
before it calls `JSON.stringify`.

The new function is not used yet; the next patch in this series will
switch profile serialization to use it.
…erialization.

This will allow us to have typed arrays in the profile and
still serialize them as regular JSON arrays whenever the profile
is serialized to JSON.
Some of our tests were auto-stringifying profiles (e.g. the ones using
fetchMock), which will produce bad results once profiles start containing
typed arrays.

Use explicit serializeProfileToJsonString calls in those places.
`RawStackTable` is being prepared to allow `frame` to be an `Int32Array`
in a later commit. `Int32Array` is fixed-size and doesn't support
`push`, so the existing "push to .frame and bump .length" pattern needs
a builder that uses a plain `number[]` during construction and converts
to the final representation via `finishRawStackTableBuilder` at the end.

Switch all stack table construction sites to use the builder. The
builder still produces a plain `number[]` for `frame` in this commit;
the type change happens in a follow-up.
@mstange mstange force-pushed the first-typed-array branch from e7d0b56 to bc1ff2e Compare June 4, 2026 18:49
This is the first typed array that we're supporting inside the profile
format.

When a profile is saved in the JsonSlabs format, it will now have this
column as a separate slab that doesn't require JSON parsing.

Profile compacting now always turns `stackTable.frame` into a typed array,
even if that column was a regular JS array in the input profile.

We still allow a regular JSON array here, because profiles stored as JSON 
cannot contain typed arrays, and we want to use the same type definition
for JSON and JSLB profiles.

Here's how this change impacts profile sizes and loading times on
this profile: https://storage.googleapis.com/profiler-get-symbols-fixtures/large-speedometer3-profile.json.gz

| Version | .jslb.gz size | .jslb size | Load time   | Profile of it loading             |
|---------|---------------|------------|-------------|-----------------------------------|
| 64      | 122 MB        | 605 MB     | 7.6 seconds | https://share.firefox.dev/4ogUKba |
| 65      | 125 MB        | 544 MB     | 6.0 seconds | https://share.firefox.dev/3Qopiem |

The compressed size has grown a small bit, but the other savings are significant:

- We no longer have 131 MB of text for the frame column in the JSON - the frame column
  is now stored in a 70 MB i32 slab.
- Less time in GZ decompression, because the uncompressed size is now smaller.
- There is a lot less time spent in TextDecoder.decode and JSON.parse, because we're
  no longer decoding and parsing 131 MB of text for the frame column.
@mstange mstange force-pushed the first-typed-array branch from bc1ff2e to d116be9 Compare June 4, 2026 18:54
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.83721% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.37%. Comparing base (93787a0) to head (940b0b2).
⚠️ Report is 60 commits behind head on main.

Files with missing lines Patch % Lines
src/utils/json-with-typed-arrays.ts 97.22% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6087      +/-   ##
==========================================
+ Coverage   83.34%   83.37%   +0.02%     
==========================================
  Files         338      339       +1     
  Lines       35868    35929      +61     
  Branches     9944    10056     +112     
==========================================
+ Hits        29895    29955      +60     
- Misses       5545     5546       +1     
  Partials      428      428              

☔ View full report in Codecov by Harness.
📢 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.

@canova canova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the delay on the reviews. It looks great to me! I Also, thanks for the detailed explanations on the commit messages!

*
* This function does not mutate rootObject.
*/
export function jsonEncodeObjectWithTypedArraysAsRegularArrays(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, that's a mouthful 😄 (but it's good to be clearer than short! 😄 )

It's annoying that JS serializes typed arrays like {"0": 1, "1": 2}! But nothing we can do about it. This solution looks good to me!

@mstange mstange enabled auto-merge June 17, 2026 19:45
@mstange mstange merged commit 924518f into firefox-devtools:main Jun 17, 2026
21 checks passed
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