[webkit-changes] [WebKit/WebKit] 402711: [JSC] Untie emitAwait() from emitYield() to reduce...

Commit Queue noreply at github.com
Fri Oct 13 15:03:13 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 402711f086a1390c86b2b4dcd21989b0f6a305fb
      https://github.com/WebKit/WebKit/commit/402711f086a1390c86b2b4dcd21989b0f6a305fb
  Author: Alexey Shvayka <ashvayka at apple.com>
  Date:   2023-10-13 (Fri, 13 Oct 2023)

  Changed paths:
    M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
    M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
    M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

  Log Message:
  -----------
  [JSC] Untie emitAwait() from emitYield() to reduce bytecode size of async functions
https://bugs.webkit.org/show_bug.cgi?id=263031
<rdar://problem/116825631>

Reviewed by Yusuke Suzuki.

Since async functions are implemented through generators for convenience, `await` keyword shares
the implementation with `yield`.

However, unlike `yield` in generators, `await` can't produce a `RETURN` completion [1], so this
patch reduces its bytecode size by simplifying ResumeMode checks. The similar change is made
to the prelude of async functions as well.

Another reason to separate implementations is that, for spec compliance [2], `yield*` in a sync
generator must reuse the received iterator result object, thus the regular `yield` would need to
wrap the value [3] in an iterator result object as well, which is unsensible to do for async
generators / functions and would bloat their bytecode size.

Also, this change a) removes unconditional (even in case of ignored result) move() from emitAwait()
and b) hoists `move(value.get(), generatorValueRegister())` in `yield*` implementation to colocate
with ResumeMode checks, making the code easier to follow and emit one less move().

No new tests, no behavior change.
This patch offers 5.1% bytecode reduction on JetStream3/async-fs subtest.

[1]: https://tc39.es/ecma262/#await
[2]: https://bugs.webkit.org/show_bug.cgi?id=174756
[3]: https://tc39.es/ecma262/#sec-createiterresultobject

* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitYield):
(JSC::BytecodeGenerator::emitAwait):
(JSC::BytecodeGenerator::emitDelegateYield):
* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h:
(JSC::BytecodeGenerator::emitAwait):
* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::FunctionNode::emitBytecode):
(JSC::YieldExprNode::emitBytecode):
(JSC::AwaitExprNode::emitBytecode):

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




More information about the webkit-changes mailing list