JSON Viewer: Profile Size only profiles the first line of a JSON Lines document
Categories
(DevTools :: JSON Viewer, defect, P3)
Tracking
(firefox155 fixed)
| Tracking | Status | |
|---|---|---|
| firefox155 | --- | fixed |
People
(Reporter: florian, Assigned: florian)
References
Details
Attachments
(1 file)
Since JSON Lines support landed in bug 2055774, the Profile Size button in the JSON Viewer produces a profile that is missing almost all of the document.
createSizeProfile in devtools/client/jsonview/json-size-profiler.mjs is a single-document scanner: parse() calls parseValue() once and then treats everything after the first value as trailing content. For a JSON Lines document it therefore only profiles the first line, and the remaining lines are attributed to a null stack handle, where recordBytesConsumed() silently discards them.
The result looks like a profile with most samples missing rather than an error: meta.fileSize is correct, but the sample weights only sum to the first line. On a 5-record, 204 byte test file the samples accounted for 40 bytes.
Two further issues follow from the same root cause:
- The sub-parsers are not bounded to a line, so
parseObject/parseArrayscan past the newline. A truncated record (the common case for a streamed or partially downloaded .jsonl file) consumes the valid records that follow it, so those records disappear from the profile. - The scanner is more permissive than
JSON.parse, so some lines the viewer renders asJsonlLineErrorare profiled as valid, and the profile disagrees with what the viewer shows.
Fix: pass JSONView.isJsonlines through to createSizeProfile, loop over records with each record bounded to its own line, decide record validity with JSON.parse so the profile agrees with the viewer, and attribute record separators and invalid lines to their own frames instead of dropping them.
| Assignee | ||
Comment 1•2 months ago
|
||
createSizeProfile() parsed a single JSON value and treated the rest of the
document as trailing content, so for a JSON Lines document it only profiled the
first line. The remaining lines were attributed to a null stack handle, which
recordBytesConsumed() discards, making the profile look like it was missing most
of its samples while meta.fileSize stayed correct.
Pass JSONView.isJsonlines through to createSizeProfile() and loop over the
records. Each record is bounded to its own line via the new endPos limit, so a
malformed record can no longer consume the records that follow it, and record
validity is decided with JSON.parse so that the profile agrees with what the
viewer renders as an error. Record separators and invalid lines are attributed
to their own frames rather than dropped.
All records share the top-level "json" path, so a property is aggregated across
every record and the frame count stays bounded by the shape of the records
rather than by their number.
Updated•2 months ago
|
Updated•1 month ago
|
Description
•