Repository navigation
Conversation
The Perfetto trace was exported as a JSON array of numbers, which makes jsonEncode do roughly two string writes per trace byte and can exhaust the browser's memory for large traces. Export it as a base64 string under a new key instead, and keep reading the legacy list format so older files still load. Also: - Only encode the bytes in a ByteData view when converting to base64. - Allocate Uint8ListRingBuffer.merged once at its exact size. - Show an error instead of crashing when the data is too large to export. - Revoke the download Blob URL after the download starts. Fixes flutter#10010
Contributor
There was a problem hiding this comment.
Code Review
This pull request optimizes memory usage and file size when saving and loading performance trace data. It introduces base64 encoding for the Perfetto trace binary instead of the legacy JSON array of numbers, while maintaining backwards compatibility. It also optimizes buffer merging in Uint8ListRingBuffer, ensures only the active view of ByteData is encoded, handles potential RangeError during large exports, and defers revoking object URLs on the web to prevent download cancellations. There are no review comments, so I have no feedback to provide.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10010
Saving Performance data wrote the Perfetto trace as a JSON array of numbers.
jsonEncodethen does roughly two string writes per trace byte, so a ~50 MB trace becomes a ~184 MB file and a very large number of string fragments in the browser, which is what runs the tab out of memory.This changes the export to:
traceBinaryBase64key (about 1.33x the trace size instead of about 3.7x).toJson()keeps aByteDataview and the existingtoEncodabledoes the base64 step, so "Review History" on disconnect still holds the trace without copying it.traceBinarylist format, so existing exported files still load. Older DevTools versions opening a new file will see no trace rather than throwing a type error, because the key is different.ByteDataEncodeDecodeto encode only the bytes in the view, not the whole backing buffer.Uint8ListRingBuffer.mergedonce at its exact size instead of lettingBytesBuilderround up to a power of two.Not changed: import still reads the whole file as one string, and traces over roughly 400 MB would need a different file format.
Tests: added round-trip tests for the new format, the legacy list and
Uint8Listinputs, an in-memoryByteData, a sub-view of a larger buffer, and a size check. Also updated the existingtoJsonassertion. I have not yet measured the memory difference in a browser against a real 2 minute recording.Pre-launch Checklist
General checklist
///).Issues checklist
Tests checklist
Feature-change checklist
packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md.