perf(measurement): line-metrics cache stop-add instead of clear-on-overflow (F13 cache)#145
Merged
Merged
Conversation
…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.)
3176d71 to
25bfecf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.get()path — so no hot-path cost.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
LinkedHashMapLRU. That was dropped after review: access-order reorders the structure on everyget()— 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).