Skip to content

perf: cache SharedString table as O(1) List on first access - #290

Open
IoannisMaras wants to merge 1 commit into
iOfficeAI:mainfrom
IoannisMaras:perf/sharedstring-o1-cache-clean
Open

perf: cache SharedString table as O(1) List on first access#290
IoannisMaras wants to merge 1 commit into
iOfficeAI:mainfrom
IoannisMaras:perf/sharedstring-o1-cache-clean

Conversation

@IoannisMaras

Copy link
Copy Markdown

Every cell read and rich-text span format calls SharedStringTable.Elements<SharedStringItem>().ElementAtOrDefault(idx). In the OpenXML SDK, SharedStringTable is a linked list. Walking from node 0 to `idx` on every cell performs millions of redundant pointer hops.

Fix

  1. Cache SharedStringTable in a random-access `List` on first access (`GetSharedStringItemCache()`).
  2. Update `GetCellDisplayValue` and `TryBuildRichTextHtml` to use the O(1) cache.
  3. Call `InvalidateSharedStringCache()` whenever new entries are appended (`add cell`), preserving 100% write correctness.

5-Run Benchmark Results

  • `view text`: 1369ms -> 933ms (~436ms saved, 1.47x speedup)
  • `view html`: 1851ms -> 1090ms (~761ms saved, 1.70x speedup)
  • `view screenshot`: 3078ms -> 2372ms (~706ms saved, 1.30x speedup)"

@IoannisMaras
IoannisMaras force-pushed the perf/sharedstring-o1-cache-clean branch from 737c79f to fb1e2d8 Compare August 7, 2026 21:43
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