Reduce notebook memory footprint #21319
Open
+84
−71
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.
Summary
Reduce the memory footprint of
NotebookIndexfromO(lines)toO(cells).The
NotebookIndexstores a mapping from rows in the concatenated notebook documentto the relative row numbers within each cell and from absolute line number to the corresponding cell.
The way this is implemented today is by having a vector with one entry for every absolute row number
where the value is the index of the cell. While this allows
O(1)lookup, it does require an entry for every single line.This PR rewrites our representation (and uses one
Vecinstead of two) to only store thestart line number per cell and use a binary search to find to which cell a line number belongs.
This makes lookups slightly slower (from
O(1)toO(log(n))but reduces memory usagefrom
O(rows)toO(cells).I noticed this improvement when working on ty's notebook support but decided to extract it into its own PR to make reviewing easier.
Test Plan
Existing tests