Skip to content

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

Open
mstange wants to merge 6 commits into
firefox-devtools:mainfrom
mstange:first-typed-array
Open

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

Conversation

@mstange
Copy link
Copy Markdown
Contributor

@mstange mstange commented Jun 4, 2026

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
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

❌ Patch coverage is 98.83721% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.71%. Comparing base (2fd6ce9) to head (d116be9).
⚠️ Report is 4 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.70%   83.71%   +0.01%     
==========================================
  Files         337      339       +2     
  Lines       35575    35754     +179     
  Branches     9971    10026      +55     
==========================================
+ Hits        29778    29933     +155     
- Misses       5369     5393      +24     
  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.

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.

1 participant