From 4975b1fd2e8dcc86a9c34edfca7c0bfacfebb113 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 17 Oct 2024 23:53:15 -0700 Subject: [PATCH] Revert "Experiment: keep flushing immediate queue" This reverts commit cd5c6693b591de60c22f770c9a11080b0c48445a. --- src/bun.js/event_loop.zig | 24 +++++++----------------- src/cli/test_command.zig | 6 ++---- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index f397730462..98756f1c26 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -1359,9 +1359,8 @@ pub const EventLoop = struct { var ctx = this.virtual_machine; var loop = this.usocketsLoop(); - while (this.flushImmediateQueue()) { - this.tickImmediateTasks(ctx); - } + this.flushImmediateQueue(); + this.tickImmediateTasks(ctx); if (comptime Environment.isPosix) { // Some tasks need to keep the event loop alive for one more tick. @@ -1398,28 +1397,22 @@ pub const EventLoop = struct { ctx.timer.drainTimers(ctx); } - while (this.flushImmediateQueue()) { - this.tickImmediateTasks(ctx); - } - + this.flushImmediateQueue(); ctx.onAfterEventLoop(); } - pub fn flushImmediateQueue(this: *EventLoop) bool { + pub fn flushImmediateQueue(this: *EventLoop) void { // If we can get away with swapping the queues, do that rather than copying the data if (this.immediate_tasks.count > 0) { this.immediate_tasks.write(this.next_immediate_tasks.readableSlice(0)) catch unreachable; this.next_immediate_tasks.head = 0; this.next_immediate_tasks.count = 0; - return true; } else if (this.next_immediate_tasks.count > 0) { const prev_immediate = this.immediate_tasks; const next_immediate = this.next_immediate_tasks; this.immediate_tasks = next_immediate; this.next_immediate_tasks = prev_immediate; - return true; } - return false; } pub fn tickPossiblyForever(this: *EventLoop) void { @@ -1457,9 +1450,8 @@ pub const EventLoop = struct { pub fn autoTickActive(this: *EventLoop) void { var loop = this.usocketsLoop(); var ctx = this.virtual_machine; - while (this.flushImmediateQueue()) { - this.tickImmediateTasks(ctx); - } + this.flushImmediateQueue(); + this.tickImmediateTasks(ctx); if (comptime Environment.isPosix) { const pending_unref = ctx.pending_unref_counter; @@ -1482,9 +1474,7 @@ pub const EventLoop = struct { ctx.timer.drainTimers(ctx); } - while (this.flushImmediateQueue()) { - this.tickImmediateTasks(ctx); - } + this.flushImmediateQueue(); ctx.onAfterEventLoop(); } diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index 837e7fd523..b0f1000b5b 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -1244,7 +1244,7 @@ pub const TestCommand = struct { vm.eventLoop().tick(); var prev_unhandled_count = vm.unhandled_error_counter; - while (vm.active_tasks > 0) : (_ = vm.eventLoop().flushImmediateQueue()) { + while (vm.active_tasks > 0) : (vm.eventLoop().flushImmediateQueue()) { if (!jest.Jest.runner.?.has_pending_tests) { jest.Jest.runner.?.drain(); } @@ -1264,9 +1264,7 @@ pub const TestCommand = struct { } } - while (vm.eventLoop().flushImmediateQueue()) { - vm.eventLoop().tickImmediateTasks(vm); - } + vm.eventLoop().flushImmediateQueue(); switch (vm.aggressive_garbage_collection) { .none => {},