Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 42379632e9d06838b326df8fd52f1cd6db00eb2b
      
https://github.com/WebKit/WebKit/commit/42379632e9d06838b326df8fd52f1cd6db00eb2b
  Author: Wenson Hsieh <[email protected]>
  Date:   2026-06-17 (Wed, 17 Jun 2026)

  Changed paths:
    M Source/WebCore/page/text-extraction/TextExtraction.cpp
    M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/TextExtractionTests.mm

  Log Message:
  -----------
  TextExtraction::extractRecursive sometimes takes too long scanning 
WeakHash(Set|Map) for null entries
https://bugs.webkit.org/show_bug.cgi?id=317363
rdar://179924406

Reviewed by Abrar Rahman Protyasha.

When traversing through the DOM during text context retrieval, we build up 
several weak hash maps
along the way, some of which might grow quite large (i.e. proportional to the 
number nodes in the
DOM). Since we end up mutating this set and forcing it to 
`removeNullReferences` while traversing
through the DOM, with a worst-case performance of `O(n^2)` (`n` representing 
the size of the DOM).

Fix this by:

1.  Replacing these weak maps with regular `HashMap` instead — it's not 
actually necessary to make
    these weak in the first place, since they're only stored temporarily on the 
stack during
    traversal.

2.  Remove `visitedContainers` — this was added in an attempt to fix (a 
then-mysterious) infinite
    recursion under `TextExtraction::extractRecursive`, which we later 
root-caused and fixed in
    314250@main. As such, this hardening should not be needed at all.

* Source/WebCore/page/text-extraction/TextExtraction.cpp:
(WebCore::TextExtraction::TraversalContext::pushEnclosingBlock):
(WebCore::TextExtraction::extractRecursive):
(WebCore::TextExtraction::extractItem):

Canonical link: https://commits.webkit.org/315433@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to