-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(ts): reuse Reader whilst parsing records (#1212)
Reduces `McapStreamReader` heap usage by ~25% and boosts throughput by ~30%. This is both a refactor and perf boost, with more room for improvement, key changes: - Removes StreamBuffer, hoisted into McapStreamReader - Reuses Reader and DataView class across parse calls, only resetting them when necessary (e.g: append in McapStreamReader) - Splits `parseRecord` into small scoped parsing functions, this itself is perf neutral (slightly positive) but facilitates future monomorphic fast paths - Moves offsets tracking into Reader which is cleaner and faster ### Before ``` McapStreamReader 3.48±0.03 op/s Heap Used: 49.56±12.75 MB/op Heap Total: 41.47±11.83 MB/op ArrayBuffers: 112.95±6.87 MB/op McapIndexedReader 2.15±0.02 op/s Heap Used: 70.02±2.84 MB/op Heap Total: 58.34±3.36 MB/op ArrayBuffers: 17.86±0.76 MB/op McapIndexedReader_reverse 2.18±0.01 op/s Heap Used: 59.92±2.86 MB/op Heap Total: 39.81±1.00 MB/op ArrayBuffers: 14.58±1.42 MB/op ``` ### After ``` McapStreamReader 4.47±0.08 op/s Heap Used: 42.35±2.23 MB/op Heap Total: 32.93±3.76 MB/op ArrayBuffers: 105.93±12.19 MB/op McapIndexedReader 2.38±0.02 op/s Heap Used: 72.00±1.70 MB/op Heap Total: 55.12±2.51 MB/op ArrayBuffers: 17.86±1.85 MB/op McapIndexedReader_reverse 2.38±0.02 op/s Heap Used: 63.41±1.55 MB/op Heap Total: 39.33±0.53 MB/op ArrayBuffers: 18.40±1.60 MB/op ``` ### Followups - Simplify parsing code further after exploring monomorphic callpaths - Can further improve DataView/Reader churn in indexed readers
- Loading branch information
Showing
8 changed files
with
556 additions
and
600 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Oops, something went wrong.