Skip to content

perf(measurement): line-metrics cache stop-add instead of clear-on-overflow (F13 cache)#145

Merged
DemchaAV merged 1 commit into
developfrom
perf/measurement-cache-lru
Jun 9, 2026
Merged

perf(measurement): line-metrics cache stop-add instead of clear-on-overflow (F13 cache)#145
DemchaAV merged 1 commit into
developfrom
perf/measurement-cache-lru

Conversation

@DemchaAV

@DemchaAV DemchaAV commented Jun 8, 2026

Copy link
Copy Markdown
Owner

The process-wide line-metrics cache clear()-ed every entry once it passed 50,000 distinct styles — a non-atomic check-then-clear that is a thundering-herd recompute under concurrent rendering. It now stops inserting at the cap and keeps the existing entries.

  • Runs only on a line-metrics cache miss (insert), never on the per-measurement get() path — so no hot-path cost.
  • Measured line metrics are unchanged (byte-identical) — covered by the snapshot / visual suite.
  • Distinct styles are few in real use (a handful of font/size/decoration combos), so this only guards a pathological style explosion (>50k distinct styles).

Scoped to FontLibraryTextMeasurementSystem; no public API or behaviour change.

Dropped F9 (width-cache LRU)

The original PR also turned the per-style width cache into an access-order LinkedHashMap LRU. That was dropped after review: access-order reorders the structure on every get() — a per-hit cost on the measurement hot path — to fix a case that only triggers at >10k distinct strings per style (rare after the F1 wrapping fix). The cost lands on the common case for an edge-case benefit, so the original clear-on-overflow stays.

Verification

  • ./mvnw verify -pl . — BUILD SUCCESS, 1151 tests, 0 failures (checkstyle + SpotBugs + javadoc); snapshot/visual unchanged (values identical).

…ar-on-overflow

The process-wide line-metrics cache clear()-ed every entry once it passed 50,000
distinct styles — a non-atomic check-then-clear that is a thundering-herd recompute
under concurrent rendering. Stop inserting at the cap and keep the existing entries
instead; this runs only on a cache miss, never on the per-measurement get() path.

Measured line metrics are unchanged. Distinct styles are few in real use, so this
only guards a pathological style explosion.

Finding 13 (cache). (The width-cache LRU, Finding 9, was dropped: it added a
per-get reorder cost to the hot path for a rare-overflow benefit.)
@DemchaAV DemchaAV force-pushed the perf/measurement-cache-lru branch from 3176d71 to 25bfecf Compare June 9, 2026 00:09
@DemchaAV DemchaAV changed the title perf(measurement): bounded cache eviction instead of clear-on-overflow (F9 + F13 cache) perf(measurement): line-metrics cache stop-add instead of clear-on-overflow (F13 cache) Jun 9, 2026
@DemchaAV DemchaAV merged commit 16b40b9 into develop Jun 9, 2026
11 checks passed
@DemchaAV DemchaAV deleted the perf/measurement-cache-lru branch June 9, 2026 00:34
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