Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c1a4f50e71dcaf12038d42507fd7ea1218d37876
      
https://github.com/WebKit/WebKit/commit/c1a4f50e71dcaf12038d42507fd7ea1218d37876
  Author: Vassili Bykov <[email protected]>
  Date:   2026-03-05 (Thu, 05 Mar 2026)

  Changed paths:
    M Source/JavaScriptCore/parser/Lexer.cpp
    M Source/JavaScriptCore/parser/Lexer.h
    M Source/JavaScriptCore/parser/Parser.cpp
    M Source/JavaScriptCore/parser/Parser.h
    M Source/WTF/wtf/Forward.h
    M Source/WTF/wtf/SegmentedVector.h
    M Tools/TestWebKitAPI/CMakeLists.txt
    M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
    A Tools/TestWebKitAPI/Tests/WTF/SegmentedVector.cpp

  Log Message:
  -----------
  [JSC] Retire ScopeRef
https://bugs.webkit.org/show_bug.cgi?id=309171
rdar://171728663

Reviewed by Yusuke Suzuki.

This patch optimizes the Parser by getting rid of the ScopeRef class and the
scope access indirection it involves. It also makes Parser and Lexer classes
more cache-friendly by grouping hot fields together.

ScopeRef exists because Scopes are organized as a stack, implemented as a
WTF::Vector, and a Vector can move its elements as it grows. To deal with that,
scopes are accessed via ScopeRef instances. A ScopeRef holds a pointer to the
vector and an index, and looks up the referenced scope by index on each access.

WTF has a class SegmentedVector which doesn't move its elements. However, unlike
Vector, SegmentedVector does not support inline storage. Parser scope stack as
defined stores up to 10 elements inline, which avoids heap allocation in over
99% cases for JS3.

The key changes in this patch:

1. SegmentedVector is enhanced to allow inline storage. The default
   InlineCapacity is maintained at 0, and the code is structured so that the
   code paths at InlineCapacity = 0 are unchanged, which ensures the enhancement
   does not affect other users.

2. Parser is changed to use a SegmentedVector for its scope stack.
   InlineCapacity of 10 matches the old Vector inline capacity, and SegmentSize
   of 20 makes it allocate at most once in JS3 tests.

3. `ScopeRef` is deleted and all its users are changed to use direct `Scope*`s.
   In most cases, scope stack walking by decrementing the index becomes pointer
   chasing through Scope objects. There is one place where the new logic is
   materially different from the original: in the `baseIsSuper` branch of
   `Parser::parseMemberExpression()`, the original used stack index comparison
   while the new logic walks the scope chain. However, this is a rare case with
   no noticeable performance impact, while tracking indices to avoid pointer
   chasing would add cost across the board.

4. Lexer and Parser classes are aligned to a cache line boundary, and their
   fields are rearranged to keep the hot ones together.

Testing:

  - Tests are added for the SegmentedVector class, which previously had none
    (Tools/TestWebKitAPI/Tests/WTF/SegmentedVector.cpp).
  - Parser is validated by existing tests.

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



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

Reply via email to