[webkit-changes] [WebKit/WebKit] 3795d9: Optimize text layout in text heavy web pages
Yusuke Suzuki
noreply at github.com
Tue Mar 12 10:57:57 PDT 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 3795d9da24e4418ea3ed7f191e56e390738c6dac
https://github.com/WebKit/WebKit/commit/3795d9da24e4418ea3ed7f191e56e390738c6dac
Author: Yusuke Suzuki <ysuzuki at apple.com>
Date: 2024-03-12 (Tue, 12 Mar 2024)
Changed paths:
M Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp
M Source/WebCore/platform/graphics/FontCascade.cpp
M Source/WebCore/platform/graphics/FontCascade.h
M Source/WebCore/platform/graphics/WidthCache.h
Log Message:
-----------
Optimize text layout in text heavy web pages
https://bugs.webkit.org/show_bug.cgi?id=270612
rdar://problem/124177964
Reviewed by Chris Dumez.
This patch applies several changes.
1. isStrongDirectionalityCharacter is not used when the characters are 8Bit. We should apply isLatin1 fast path as the same to the caller.
u_charDirection is ICU function and it is quite slow.
2. Move non-cach-hitting part of FontCascade::widthForSimpleText to FontCascade::widthForSimpleTextSlow. It has GlyphBuffer, and it has
huge stack size. Let's extract the cache-hitting fast path from this function and avoid putting this on the stack.
3. This patch optimizes WidthCache.
3.1. We do not need to check MemoryPressureHandler status unless we extend the cache.
3.2. Since SmallStringKey's string size is small, we can make it much more like non-variable-length data and make it super fast.
This patch changes the layout of SmallStringKey a bit so that we hold characters in std::array<UChar, 16>. So, comparison becomes
`std::array<UChar, 16> == std::array<UChar, 16>` and because it is 32-bytes (16 size is picked for that), comparison gets done in a bulk style (e.g. 4 characters at once)
automatically via compiler and it becomes super fast. By combining hash and length into one unsigned, we keep std::pair<SmallStringKey, float> 40-bytes.
3.3. We also use WYHash for SmallStringKey's hashing. Plus, we now always hash all 16 characters (and if it is smaller than 16, then zeros follow).
WYHash::computeHashAndMaskTop8Bits can see constant 16 size, so hashing gets done in a extremely fast way without branches (since now the size is always 16).
Also, 16 is good number for WYHash since it can do 8-length hashing in a bulk way.
3.4. Making empty value of SmallStringKey zero. This allows HashMap to initialize newly rehashed table with zeroed-malloc.
* Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp:
(WebCore::Layout::TextUtil::isStrongDirectionalityCharacter):
* Source/WebCore/platform/graphics/FontCascade.cpp:
(WebCore::FontCascade::widthForSimpleTextSlow const):
(WebCore::addGlyphsFromText): Deleted.
(WebCore::FontCascade::widthForSimpleText const): Deleted.
* Source/WebCore/platform/graphics/FontCascade.h:
(WebCore::FontCascade::widthForSimpleText const):
* Source/WebCore/platform/graphics/WidthCache.h:
(WebCore::WidthCache::SmallStringKey::capacity):
(WebCore::WidthCache::SmallStringKey::SmallStringKey):
(WebCore::WidthCache::SmallStringKey::characters const):
(WebCore::WidthCache::SmallStringKey::length const):
(WebCore::WidthCache::SmallStringKey::hash const):
(WebCore::WidthCache::SmallStringKey::isHashTableDeletedValue const):
(WebCore::WidthCache::SmallStringKey::isHashTableEmptyValue const):
(WebCore::WidthCache::add):
(WebCore::WidthCache::addSlowCase):
(WebCore::operator==): Deleted.
Canonical link: https://commits.webkit.org/275987@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list