Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c2f2ad1536f484aba4af75fe0a9a31a4dd08808f
      
https://github.com/WebKit/WebKit/commit/c2f2ad1536f484aba4af75fe0a9a31a4dd08808f
  Author: Cole Carley <[email protected]>
  Date:   2026-08-12 (Wed, 12 Aug 2026)

  Changed paths:
    M Source/WebCore/editing/CachedMatchFinder.cpp
    M Source/WebCore/editing/CachedMatchFinder.h
    M Source/WebCore/editing/TextIterator.cpp
    M Source/WebCore/editing/TextIterator.h

  Log Message:
  -----------
  Improve Find in Page on very large pages
https://bugs.webkit.org/show_bug.cgi?id=321235
rdar://181159812

Reviewed by Ryosuke Niwa.

When the CachedMatchFinder has a cache miss, it has to rebuild it's
buffer using the TextIterator. It creates a vector of text runs that
is later used to to map the start and end in the buffer to a
SimpleRange in the DOM.

During buffer construction, the collected text runs store the
SimpleRanges of the current text it's adding to the buffer. This requires
calling TextIterator::range().

After taking some traces of find in page on very large pages, I found
that a majority of the time was spent in Node::computeNodeIndex(), which
is called from TextIterator::range(). This never had to be called before
the introduction of the CachedMatchFinder because we did not cache a
flattened buffer of the DOM text before.

To combat this problem, I instead store a new TextIteratorPosition, which
allows us to lazily evaluate to a SimpleRange only when we need it.
This dramatically speeds up initial buffer construction as well as other
cache misses on pages where misses are noticeable.

* Source/WebCore/editing/CachedMatchFinder.cpp:
(WebCore::CachedMatchFinder::TextRun::resolveOffsets const):
(WebCore::CachedMatchFinder::TextRun::start const):
(WebCore::CachedMatchFinder::TextRun::range const):
(WebCore::CachedMatchFinder::bufferOffsetForBoundaryPoint):
(WebCore::CachedMatchFinder::textForScope):
(WebCore::CachedMatchFinder::boundaryForOffset):
* Source/WebCore/editing/CachedMatchFinder.h:
* Source/WebCore/editing/TextIterator.cpp:
(WebCore::TextIterator::position const):
* Source/WebCore/editing/TextIterator.h:

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



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

Reply via email to