Skip to content

Bound font, shaper and kerning caches; replace test timeouts with behavior checks; add benchmarks - #2636

Merged
AdrianEPPlus merged 3 commits into
develop9from
font-fixes-2
Dec 3, 2026
Merged

AdrianEPPlus merged 3 commits into
develop9from
font-fixes-2

Conversation

@swmal

@swmal swmal commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Bound font caches and remove timing-based tests

Summary

Follow-up to the font security review (#2634). It fixes three unbounded caches and makes the font tests check behavior instead of time.

Cache fixes

  • FontStore: font names that resolve to the same file now share one parsed font, matched by content hash and a byte compare. Before, each unknown name parsed the fallback font again (~0.9 MB per name).
  • ShaperCache: uses a per-instance ThreadLocal. Dispose, or the finalizer for an abandoned engine, now releases shapers on all threads. Before, each engine leaked ~2.3 MB per thread-pool thread.
  • KerningCache: two-level key with no allocation per lookup, capped at 65,536 pairs. Results are unchanged on 560 fonts.

Tests

  • Removed all 62 [Timeout] attributes.
  • Three reference-limit tests now assert the limit itself. The collector methods are internal static so the tests can call them.
  • Two slow tests use smaller input (2 s → 32 ms, 0.6 s → 103 ms).
  • Added namespaces to two test classes and fixed a file name with a space.
  • New tests: FontStoreContentSharingTests, ShaperCacheLifetimeTests, KerningCacheTests. Each fails against the old code.

Benchmarks

New FontCacheBenchmarks:

Benchmark Before After
200 unknown font names 684 ms / 497 MB 31 ms / 15 MB
Shape 200,000 chars 138 ms / 91 MB 99 ms / 45 MB
Shape, warm cache 24.2 µs 21.4 µs

Verification

  • 722 font tests pass.
  • PDF export tests pass on net8.0 and net481.
  • All 6 target frameworks build.

@swmal swmal added this to the EPPlus 9.0 or later milestone Dec 3, 2026
@swmal swmal self-assigned this Dec 3, 2026
@swmal
swmal requested a review from AdrianEPPlus December 3, 2026 08:37

@AdrianEPPlus AdrianEPPlus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bra jobbat

@AdrianEPPlus
AdrianEPPlus merged commit bfb4811 into develop9 Dec 3, 2026
3 checks passed
@AdrianEPPlus
AdrianEPPlus deleted the font-fixes-2 branch December 3, 2026 15:01
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.

2 participants