Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 60ced441fb04e7d2479607b827d2d2edaf1b27d8
      
https://github.com/WebKit/WebKit/commit/60ced441fb04e7d2479607b827d2d2edaf1b27d8
  Author: Megan Gardner <[email protected]>
  Date:   2026-09-22 (Tue, 22 Sep 2026)

  Changed paths:
    M Source/WebCore/editing/TextIterator.cpp
    M 
Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/AttributedSubstringForProposedRange.mm

  Log Message:
  -----------
  WebContent hangs for seconds resolving a character range on pages with tens 
of thousands of sibling elements.
https://bugs.webkit.org/show_bug.cgi?id=324873
rdar://188117121

Reviewed by Pascoe.

resolveCharacterRange() called TextIterator::range() on every iteration, but 
only
reads the result for the two runs that bound the requested range.

That's expensive because range() resolves m_positionOffsetBaseNode through
Node::computeNodeIndex(), which counts previous siblings. Runs emitted
by
emitCharacter() carry a base node -- a <br> gets one from handleNonTextNode() --
so resolving the Nth such run costs N and the loop goes quadratic. Runs from
emitText() clear the base node, which is why text-only documents never hit this.

So resolve it lazily: skip ahead when neither bound is in the current run. 
That's
safe because range()'s normalization is idempotent and nothing else observes it;
handleTextRun() reads m_positionEndOffset directly, but only where the base node
is already null, and position() hands it to the caller.

Test: 
Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/AttributedSubstringForProposedRange.mm

* Source/WebCore/editing/TextIterator.cpp:
(WebCore::resolveCharacterRange):
* 
Tools/TestWebKitAPI/Tests/WebKit/WKWebView/mac/AttributedSubstringForProposedRange.mm:
(markupWithSiblingLineBreaks):
(fastestFarRangeResolution):
(TEST(AttributedSubstringForProposedRange, 
FarRangeResolutionScalesWithLineBreakCount)):

Canonical link:
https://flagged.apple.com:443/proxy?t2=DS9S7I3uw1&o=aHR0cHM6Ly9jb21taXRzLndlYmtpdC5vcmcvMzIxNjQ3QG1haW4=&emid=026da5d3-b4fc-48ef-8a47-47a6ed4608fb&c=11



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

Reply via email to