Skip to content

perf: memory optimization for Cell struct, SST, and Vec allocation#42

Merged
Nebu1eto merged 6 commits into
mainfrom
memory-optimize
Feb 10, 2026
Merged

perf: memory optimization for Cell struct, SST, and Vec allocation#42
Nebu1eto merged 6 commits into
mainfrom
memory-optimize

Conversation

@Nebu1eto

Copy link
Copy Markdown
Owner

Summary

  • Box CellFormula and InlineString in Cell struct to reduce per-cell memory from ~160B to ~80B (most cells have no formula/inline string)
  • Add shrink_to_fit() on Vec<Cell> and Vec<Row> after XML deserialization to eliminate Vec doubling overhead
  • Deduplicate SST strings using Arc<str> so strings and index_map share the same allocation
  • Skip Row.spans deserialization (#[serde(skip)]) since Excel recalculates it on open
  • Add async Workbook.open() read benchmarks alongside sync openSync() in Node.js benchmarks
  • Fix biome lint warnings (unused import, non-null assertions)

Memory Results (Node.js RSS, 50k x 20 read)

Metric Before After (sync) After (async)
Read Large Data 349.5MB 195.4MB (-44%) 17.2MB (-95%)
Read Multi-Sheet 215.8MB 132.1MB (-39%) 17.6MB (-92%)
Read Scale 100k 325.6MB 161.1MB (-51%) 0.0MB (-100%)

Test plan

  • cargo build --workspace
  • cargo test --workspace
  • cargo clippy --workspace (no warnings)
  • cargo fmt --check
  • pnpm build && pnpm test (455 tests pass)
  • pnpm check (biome, no warnings)
  • Rust benchmarks re-run
  • Node.js benchmarks re-run (sync + async)
  • COMPARISON.md updated with sync/async results

🤖 Generated with Claude Code

Nebu1eto and others added 6 commits February 10, 2026 22:50
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>
@Nebu1eto
Nebu1eto merged commit eac84fe into main Feb 10, 2026
3 checks passed
@claude

claude Bot commented Feb 10, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@Nebu1eto
Nebu1eto deleted the memory-optimize branch February 10, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant