Skip to content

Fix volatile correctness in lazy load and add roundtrip test#1747

Open
ken-swyfft wants to merge 2 commits intonissl-lab:masterfrom
swyfft-insurance:fix/ks/20260321_lazy-load-volatile-and-roundtrip-test
Open

Fix volatile correctness in lazy load and add roundtrip test#1747
ken-swyfft wants to merge 2 commits intonissl-lab:masterfrom
swyfft-insurance:fix/ks/20260321_lazy-load-volatile-and-roundtrip-test

Conversation

@ken-swyfft
Copy link
Contributor

Summary

Follow-up to #1741 (Sheet Lazy Loading):

  • Add volatile to _worksheetLoaded — The double-checked locking pattern in EnsureWorksheetLoaded() reads _worksheetLoaded outside the lock. Without volatile, on ARM platforms (.NET on Apple Silicon, Graviton, etc.) the CPU's weaker memory ordering could allow a thread to see _worksheetLoaded = true before the worksheet fields are fully initialized. On x86/x64 this is a no-op due to strong ordering, so no perf impact.

  • Add SaveWithoutAccessPreservesUntouchedSheets test — Creates a 3-sheet workbook, re-opens it, modifies only sheet 1, saves, and verifies sheets 0 and 2 survived the roundtrip with original data intact. This exercises the PrepareForCommit() and Commit() early-return paths that skip re-serialization of unaccessed sheets — the core value proposition of lazy loading.

Test plan

  • All 10 TestXSSFSheetLazyLoad tests pass on both net8.0 and net472
  • CI green on Ubuntu and Windows

🤖 Generated with Claude Code

- Add volatile to _worksheetLoaded for correct double-checked locking
  on ARM/.NET platforms where memory ordering is weaker than x86
- Add SaveWithoutAccessPreservesUntouchedSheets test verifying that
  opening a workbook, modifying one sheet, and saving preserves
  untouched sheets' data through the lazy load Commit() early-return

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tonyqus tonyqus added this to the NPOI 2.8.0 milestone Mar 22, 2026
…s/20260321_lazy-load-volatile-and-roundtrip-test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants