Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drain microtasks again after deferred tasks run #16857

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/bun.js/event_loop.zig
Original file line number Diff line number Diff line change
@@ -743,9 +743,10 @@ pub const DeferredTaskQueue = struct {
return this.map.swapRemove(ctx);
}

pub fn run(this: *DeferredTaskQueue) void {
pub fn run(this: *DeferredTaskQueue) bool {
var i: usize = 0;
var last = this.map.count();
const has_any = last > 0;
while (i < last) {
const key = this.map.keys()[i] orelse {
this.map.swapRemoveAt(i);
@@ -760,6 +761,8 @@ pub const DeferredTaskQueue = struct {
i += 1;
}
}

return has_any;
}

pub fn deinit(this: *DeferredTaskQueue) void {
@@ -877,7 +880,10 @@ pub const EventLoop = struct {

jsc_vm.releaseWeakRefs();
JSC__JSGlobalObject__drainMicrotasks(globalObject);
this.deferred_tasks.run();
this.drainMicrotasksWithGlobal(this.global, this.virtual_machine.jsc);
if (this.deferred_tasks.run()) {
this.drainMicrotasksWithGlobal(this.global, this.virtual_machine.jsc);
}

if (comptime bun.Environment.isDebug) {
this.debug.drain_microtasks_count_outside_tick_queue += @as(usize, @intFromBool(!this.debug.is_inside_tick_queue));