perf: memory optimization for Cell struct, SST, and Vec allocation#42
Merged
Conversation
Wrap Cell.f (Option<CellFormula>) and Cell.is (Option<InlineString>) in Box to reduce per-cell memory from ~160 bytes to ~88 bytes. Most cells have no formula or inline string, so the Box indirection saves ~72-88 bytes per cell by avoiding inline storage of rarely-used fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Call shrink_to_fit() on Row.cells and SheetData.rows immediately after XML deserialization to release excess capacity from Vec doubling strategy. This reduces memory waste by ~40-48MB for large workbooks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace Vec<String> + HashMap<String, usize> with Vec<Arc<str>> + HashMap<Arc<str>, usize> in SharedStringTable. Both collections now share the same string allocation via Arc reference counting, eliminating ~28MB of duplicate string storage for large workbooks. Arc (not Rc) is used because napi-rs async functions require Send+Sync. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Apply serde(skip) to Row.spans field so it is neither deserialized nor serialized. Excel auto-recalculates spans on open, so this field is never needed at runtime. Saves ~24-48 bytes per row for parsed sheets. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Memory reduced ~44-47% for large read scenarios: - Read Large Data (50k x 20): 349.5MB -> 195.4MB (-44%) - Read Multi-Sheet (10 x 5k): 215.8MB -> 114.3MB (-47%) - Read Scale 100k rows: 325.6MB -> 175.1MB (-46%) - Read Heavy Styles: 15.2MB -> 5.3MB (-65%) - Random-access read: 27.2MB -> 12.4MB (-54%) No performance regression in read/write time benchmarks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add async read benchmarks alongside existing sync openSync() in Node.js benchmarks. Fix biome warnings (unused import, non-null assertions). Update COMPARISON.md with sync vs async results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
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.
Summary
CellFormulaandInlineStringinCellstruct to reduce per-cell memory from ~160B to ~80B (most cells have no formula/inline string)shrink_to_fit()onVec<Cell>andVec<Row>after XML deserialization to eliminate Vec doubling overheadArc<str>sostringsandindex_mapshare the same allocationRow.spansdeserialization (#[serde(skip)]) since Excel recalculates it on openWorkbook.open()read benchmarks alongside syncopenSync()in Node.js benchmarksMemory Results (Node.js RSS, 50k x 20 read)
Test plan
cargo build --workspacecargo test --workspacecargo clippy --workspace(no warnings)cargo fmt --checkpnpm build && pnpm test(455 tests pass)pnpm check(biome, no warnings)🤖 Generated with Claude Code