Repository navigation
perf(export): hand large copies to the isolate in chunks (#1537) - #1659
Merged
Merged
Conversation
formatAsync ran one Isolate.run whose closure captured all rows. The captured object graph is copied on the calling isolate before the worker starts, so copying 50,000 x 20 cells to the clipboard stopped the UI for about 20-30 ms. Above about 20,000 cells (handOffCells) the rows now go over in chunks of that size, each formatted on its own isolate, with the event loop running between them; the parts are joined. formatChunk produces each part so that the join is exactly the format* output: the header (and JSON's '[') in the first chunk, ']' in the last, the JSON items split out of the indented array. The isolate calls live in separate functions so a closure captures only its chunk, not formatAsync's whole rows. Standalone Dart AOT, 50,000 x 20, Timer.periodic(1 ms) on the caller: longest gap 21 ms with one closure, 2-4 ms with 1,000-row chunks; total time ~85 ms -> ~55 ms.
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.
Closes #1537. The dead
resultGridAsCsvAsyncwas already removed in #1606; this is the other half, the hand-off stall.What stalls
DataExportService.formatAsyncran oneIsolate.runwhose closure captured all rows. The captured object graph is copied on the calling (UI) isolate before the worker starts, so copying 50,000 × 20 cells to the clipboard stopped the UI for ~20–30 ms.Change
handOffCells(20,000 cells) nothing changes: one isolate, the whole table.formatChunkmakes each part so that the join is exactly whatformatCsv/formatJson/formatMarkdownTable/formatSqlInsertDumpgive for all rows:[in the first chunk,]in the last, and the items are cut out of the indented array;formatAsyncwould carry the wholerowsalong; in my first measurement that made chunking slower than no chunking.formatMarkdownTableis split into header and rows helpers. Its output is unchanged.Measured
Standalone Dart AOT, the issue's shape: 50,000 × 20 CSV,
Timer.periodic(1 ms)on the calling isolate, longest gap during the call, 3 runs.20,000 cells per chunk is the 1,000-row case at 20 columns. The clipboard call itself (
Clipboard.setDatawith one big string) is not part of this.Tests (
test/shared/data_export_service_test.dart)For every format, chunks of 1, 3, 7, 22 and 23 rows joined equal the whole document. The rows include quotes, commas, newlines,
|,NULLand short rows.formatAsyncon ~40,000 cells (3 chunks) equals the whole document.Not run with
flutter testlocally; CI decides.