Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 9679818e5852879256b7e4723c7d4e56417f2420
      
https://github.com/WebKit/WebKit/commit/9679818e5852879256b7e4723c7d4e56417f2420
  Author: Brent Fulgham <[email protected]>
  Date:   2026-09-24 (Thu, 24 Sep 2026)

  Changed paths:
    A PerformanceTests/DOM/select-append-options.html
    A PerformanceTests/Parser/html-parser-long-text-runs.html
    A PerformanceTests/Parser/innerHTML-setter-character-references.html
    M 
Source/JavaScriptCore/b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp
    M Source/WTF/wtf/SparseBitVector.h
    M Source/WTF/wtf/URLParser.cpp
    M Source/WebCore/html/HTMLSelectElement.cpp
    M Source/WebCore/html/HTMLVideoElement.cpp
    M Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp
    M Source/WebCore/html/parser/HTMLToken.h
    M Source/WebCore/layout/formattingContexts/inline/InlineContentBreaker.cpp
    M Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp
    M Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp
    M Source/WebCore/page/ResizeObserver.cpp
    M Source/WebCore/page/scrolling/ScrollingTreeNode.cpp
    M Source/WebCore/platform/graphics/GraphicsLayer.cpp
    M 
Source/WebCore/platform/graphics/skia/SkiaCompositingLayerImageSetBatch.cpp
    M Source/WebGPU/WebGPU/RenderPassEncoder.mm
    M Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp

  Log Message:
  -----------
  Vector users should prefer shrinking to clearing for reused vectors
https://bugs.webkit.org/show_bug.cgi?id=325059
rdar://188226887

Reviewed by Yusuke Suzuki.

Vector::clear() is shrinkCapacity(0), so it frees the backing buffer. When a 
retained vector
is emptied and then refilled every frame, layout, commit, or compile pass, each 
refill pays
for a free and a fresh malloc (plus regrowth). shrink(0) empties the vector but 
keeps its
capacity for the next fill.

This patch switches to shrink(0) at sites where the owner is short-lived (a 
per-frame,
per-layout, or per-compile object) or where the vector refills to a similar 
size every cycle.
Sites where clear() intentionally releases memory are left alone, as are 
long-lived or
numerous objects whose vector usually stays empty after the clear.

Two parser sites get a related fix. HTMLToken::clear() now keeps its buffer, so 
a text or comment
token longer than the 256-character inline capacity no longer regrows from 
scratch every time;
buffers grown past 16K characters are still released. 
HTMLFastPathParser::scanEscapedText()
moved its buffer into a temporary that String copied from and then freed; it 
now copies from
the retained buffer directly.

Measured on WebKitTestRunner (Release, median of three interleaved A/B rounds):
    Parser/html-parser-long-text-runs:                  +7.1%
    Parser/innerHTML-setter-character-references:       +4.3%
    DOM/select-append-options:                         +18.4% 
(HTMLSelectElement::recalcListItems)
Speedometer 3.1 and the inline-layout PerformanceTests are neutral.

No change in behavior, so no new layout tests.

* PerformanceTests/DOM/select-append-options.html: Added.
* PerformanceTests/Parser/html-parser-long-text-runs.html: Added.
* PerformanceTests/Parser/innerHTML-setter-character-references.html: Added.
* Source/JavaScriptCore/b3/air/AirAllocateRegistersAndStackAndGenerateCode.cpp:
(JSC::B3::Air::GenerateAndAllocateRegisters::prepareForGeneration):
* Source/WTF/wtf/SparseBitVector.h:
(WTF::SparseBitVector::clear):
* Source/WTF/wtf/URLParser.cpp:
(WTF::URLParser::copyURLPartsUntil):
(WTF::URLParser::parse):
* Source/WebCore/html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::recalcListItems const):
* Source/WebCore/html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::serviceRequestVideoFrameCallbacks):
* Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp:
(WebCore::HTMLFastPathParser::scanEscapedText):
* Source/WebCore/html/parser/HTMLToken.h:
(WebCore::HTMLToken::clear):
* Source/WebCore/layout/formattingContexts/inline/InlineContentBreaker.cpp:
(WebCore::Layout::InlineContentBreaker::ContinuousContent::reset):
* Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp:
(WebCore::Layout::InlineItemsBuilder::adjustInlineItemsForWhiteSpaceTrim):
* Source/WebCore/layout/formattingContexts/inline/InlineLine.cpp:
(WebCore::Layout::Line::initialize):
* Source/WebCore/page/ResizeObserver.cpp:
(WebCore::ResizeObserver::deliverObservations):
* Source/WebCore/page/scrolling/ScrollingTreeNode.cpp:
(WebCore::ScrollingTreeNode::removeAllChildren):
* Source/WebCore/platform/graphics/GraphicsLayer.cpp:
(WebCore::GraphicsLayer::removeAllChildren):
* Source/WebCore/platform/graphics/skia/SkiaCompositingLayerImageSetBatch.cpp:
(WebCore::SkiaCompositingLayerImageSetBatch::flushIfNeeded):
* Source/WebGPU/WebGPU/RenderPassEncoder.mm:
(WebGPU::RenderPassEncoder::splitRenderPass):
(WebGPU::RenderPassEncoder::executeBundles):
* Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
(WebKit::RemoteRenderingBackendProxy::endPreparingImageBufferSetsForDisplay):

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



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

Reply via email to