Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c823243598c5b0ada8561918280e9a1d0649000d
      
https://github.com/WebKit/WebKit/commit/c823243598c5b0ada8561918280e9a1d0649000d
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-08-19 (Wed, 19 Aug 2026)

  Changed paths:
    M Source/JavaScriptCore/API/tests/testapi.mm
    M Source/JavaScriptCore/runtime/CodeCache.cpp

  Log Message:
  -----------
  [JSC] Bytecode cache should generate `CodeForConstruct` for class constructors
https://bugs.webkit.org/show_bug.cgi?id=193823

Reviewed by Yusuke Suzuki.

generateUnlinkedCodeBlockForFunctions only generates the CodeForCall variant of 
every function.
For a class constructor that variant is just the "Cannot call a class 
constructor" throw, emitted
before the body, so the cache holds neither the construct code nor the 
functions nested in the
constructor body. Every `new C()` from a bytecode-cached program misses the 
cache and reparses
the constructor from source; the implicit default constructor is reparsed from 
the builtin source too.

Generate CodeForConstruct instead when the executable is a class constructor. 
Calling a class
constructor throws, so nothing is lost. The async-function early return becomes 
unreachable and is
removed. Ordinary functions still get CodeForCall only, since whether they are 
constructed is not
known at cache time.

Constructing 182 three.js classes from a cached program: 253 -> 4 parses, 14.5 
ms -> 10.3 ms.
babylon.js ES6 startup: 133 -> 9 parses, 30.7 ms -> 27.8 ms. Cache size grows 
by the previously
missing constructor bodies (three.js +10.8%, a 50 MB application bundle +0.5%).

Test: Source/JavaScriptCore/API/tests/testapi.mm

* Source/JavaScriptCore/API/tests/testapi.mm:
(testBytecodeCachedClassConstructorsDontReparse):
(testObjectiveCAPI):
* Source/JavaScriptCore/runtime/CodeCache.cpp:
(JSC::generateUnlinkedCodeBlockForFunctions):

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



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

Reply via email to