Closed Bug 2060529 Opened 2 months ago Closed 2 months ago

JSON Viewer: Profile Size only profiles the first line of a JSON Lines document

Categories

(DevTools :: JSON Viewer, defect, P3)

defect

Tracking

(firefox155 fixed)

RESOLVED FIXED
155 Branch
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 / parseArray scan 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 as JsonlLineError are 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.

Size profile of this file without and with the fix.

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.

Severity: -- → S3
Priority: -- → P3
Pushed by fqueze@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/cf6f1c57c541 https://hg.mozilla.org/integration/autoland/rev/eb70e6238b3b Profile every record of a JSON Lines document in the JSON Viewer. r=devtools-reviewers,nchevobbe
Status: ASSIGNED → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 155 Branch
QA Whiteboard: [qa-triage-done-c156/b155]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: