mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 18:50:50 +00:00
LibJS: Skip iteration result allocation in AsyncFunctionDriverWrapper
- Create less GC pressure by making each `await` in async function skip iteration result object allocation. - Skip uncached `Object::get()` calls to extract `value` and `done` from the iteration result object. With this change, following function goes 30% faster on my computer: ```js (async () => { const resolved = Promise.resolve(); for (let i = 0; i < 5_000_000; i++) { await resolved; } })(); ```
This commit is contained in:
parent
286a9d8101
commit
4c789ac689
Notes:
github-actions[bot]
2025-05-09 10:31:18 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 4c789ac689
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4663
7 changed files with 47 additions and 28 deletions
|
@ -21,8 +21,20 @@ public:
|
|||
virtual ~GeneratorObject() override = default;
|
||||
void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
ThrowCompletionOr<Value> resume(VM&, Value value, Optional<StringView> const& generator_brand);
|
||||
ThrowCompletionOr<Value> resume_abrupt(VM&, JS::Completion abrupt_completion, Optional<StringView> const& generator_brand);
|
||||
struct IterationResult {
|
||||
IterationResult() = delete;
|
||||
explicit IterationResult(Value value, bool done)
|
||||
: done(done)
|
||||
, value(value)
|
||||
{
|
||||
}
|
||||
|
||||
bool done { false };
|
||||
Value value;
|
||||
};
|
||||
|
||||
ThrowCompletionOr<IterationResult> resume(VM&, Value value, Optional<StringView> const& generator_brand);
|
||||
ThrowCompletionOr<IterationResult> resume_abrupt(VM&, JS::Completion abrupt_completion, Optional<StringView> const& generator_brand);
|
||||
|
||||
enum class GeneratorState {
|
||||
SuspendedStart,
|
||||
|
@ -37,7 +49,7 @@ protected:
|
|||
GeneratorObject(Realm&, Object& prototype, NonnullOwnPtr<ExecutionContext>, Optional<StringView> generator_brand = {});
|
||||
|
||||
ThrowCompletionOr<GeneratorState> validate(VM&, Optional<StringView> const& generator_brand);
|
||||
virtual ThrowCompletionOr<Value> execute(VM&, JS::Completion const& completion);
|
||||
virtual ThrowCompletionOr<IterationResult> execute(VM&, JS::Completion const& completion);
|
||||
|
||||
private:
|
||||
NonnullOwnPtr<ExecutionContext> m_execution_context;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue