Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: b0212ef741e072bf886c5d5a065875245e072a18
https://github.com/WebKit/WebKit/commit/b0212ef741e072bf886c5d5a065875245e072a18
Author: Nathan Solomon <[email protected]>
Date: 2026-08-25 (Tue, 25 Aug 2026)
Changed paths:
A
LayoutTests/fast/inline/inline-item-width-cache-stale-after-font-cache-invalidation-expected.txt
A
LayoutTests/fast/inline/inline-item-width-cache-stale-after-font-cache-invalidation.html
M LayoutTests/platform/glib/TestExpectations
M Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp
M Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.h
M
Source/WebCore/layout/formattingContexts/inline/text/TextBreakingPositionCache.cpp
M
Source/WebCore/layout/formattingContexts/inline/text/TextBreakingPositionCache.h
M Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp
M Source/WebCore/platform/graphics/FontCascadeCache.cpp
M Source/WebCore/platform/graphics/FontCascadeCache.h
Log Message:
-----------
Cache InlineTextItem widths per inline text box content to speed up
retrieving cached widths
https://bugs.webkit.org/show_bug.cgi?id=322063
rdar://184939583
Reviewed by Alan Baradlay.
On relayout, we rebuild the InlineItemsList using the
TextBreakingPositionCache. We
already utilize the glyphGeometryCache to retrieve the cached width of an
inlineTextBox's
content that we have seen before and it already has a high hit rate. However,
we query
this cache essentially per word. The overhead of retrieving the cached width
for workloads
with large amounts of text can be significant. To speed up the performance of
retrieving
cached widths, change the value of TextBreakingPositionCache to also hold a
list, where
each element is for each FontCascade of the keyed text content, and each of
these elements
holds a list of non-whitespace widths.
When we populate the TextBreakingPositionCache for the first time or rebuild the
inlineItemList using the TextBreakingPositionCache and don't already have an
entry for the
cached widths, populate the cache with all the non whitespace widths for a
given inline
text box. Then, when we rebuild the InlineItems list during relayout and use the
TextBreakingPositionCache, use the list of cached widths to avoid calling
TextUtil::width() (and its per-word glyphGeometryCache lookup) for each
InlineTextItem.
This improves locality of fetching and reading the cached widths compared to
just using
glyphGeometryCache. The glyphGeometryCache is still used as fallback if the
cached widths
lookup misses.
* Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp:
(WebCore::Layout::textBoxMayHaveGlyphOverflow):
(WebCore::Layout::inlineTextBoxWidthsAreCacheable):
(WebCore::Layout::fontCascadeIdentifier):
(WebCore::Layout::InlineItemsBuilder::computeInlineTextItemWidthsAndTextSpacing):
(WebCore::Layout::InlineItemsBuilder::buildInlineItemListForTextFromBreakingPositionsCache):
(WebCore::Layout::InlineItemsBuilder::handleTextContent):
(WebCore::Layout::collectWidthsFromBuiltItems):
(WebCore::Layout::InlineItemsBuilder::populateBreakingPositionCache):
* Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.h:
*
Source/WebCore/layout/formattingContexts/inline/text/TextBreakingPositionCache.cpp:
(WebCore::Layout::TextBreakingPositionCache::Entry::widths const):
(WebCore::Layout::widthsBytes):
(WebCore::Layout::TextBreakingPositionCache::addWidths):
(WebCore::Layout::TextBreakingPositionCache::approximateEntrySizeBytes):
(WebCore::Layout::TextBreakingPositionCache::evict):
(WebCore::Layout::TextBreakingPositionCache::set):
(WebCore::Layout::TextBreakingPositionCache::get const):
(WebCore::Layout::TextBreakingPositionCache::clearWidthsIfGenerationChanged):
(WebCore::Layout::TextBreakingPositionCache::widths):
*
Source/WebCore/layout/formattingContexts/inline/text/TextBreakingPositionCache.h:
(WebCore::Layout::TextBreakingPositionCache::Entry::Entry):
* Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::~LineLayout):
* Source/WebCore/platform/graphics/FontCascadeCache.cpp:
(WebCore::makeFontCascadeCacheKey):
* Source/WebCore/platform/graphics/FontCascadeCache.h:
*
LayoutTests/fast/inline/inline-item-width-cache-stale-after-font-cache-invalidation-expected.txt:
Added.
*
LayoutTests/fast/inline/inline-item-width-cache-stale-after-font-cache-invalidation.html:
Added.
* LayoutTests/platform/glib/TestExpectations:
Canonical link: https://commits.webkit.org/319820@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications