From 0a125c514d8e0cabd2e6a8b1cbf6887f97399b1a Mon Sep 17 00:00:00 2001 From: cirospaciari Date: Thu, 7 Sep 2023 17:41:50 -0400 Subject: only schedule if queue is not empty --- src/bun.js/webcore/response.zig | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 4766d2a2d..c9dcb668f 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -680,7 +680,6 @@ pub const Fetch = struct { response_buffer: MutableString = undefined, // all shedule buffers are stored here when not streaming scheduled_response_buffer: MutableString = undefined, - has_schedule_callback: std.atomic.Atomic(bool) = std.atomic.Atomic(bool).init(false), /// response strong ref response: JSC.Strong = .{}, /// stream strong ref if any is available @@ -1080,17 +1079,10 @@ pub const Fetch = struct { JSC.markBinding(@src()); log("onProgressUpdate", .{}); - var has_more = false; while (this.result_queue.pop()) |result| { defer result.deinit(); - has_more = result.has_more; this.processResult(result); } - - if (has_more) { - this.has_schedule_callback.store(false, .Monotonic); - return; - } } pub fn checkServerIdentity(this: *FetchTasklet, certificate_info: HTTPClient.CertificateInfo, result: *HTTPClientQueueResult) bool { @@ -1522,14 +1514,12 @@ pub const Fetch = struct { .body = MutableString.initCopy(bun.default_allocator, result.body.?.*.list.items) catch @panic("OOM"), }; task.size_hint = item.getSizeHint(); + const is_empty = task.result_queue.isEmpty(); task.result_queue.push(item); task.response_buffer.reset(); - if (task.has_schedule_callback.compareAndSwap(false, true, .Acquire, .Monotonic)) |has_schedule_callback| { - if (has_schedule_callback) { - return; - } + if (is_empty) { + task.javascript_vm.eventLoop().enqueueTaskConcurrent(task.concurrent_task.from(task, .manual_deinit)); } - task.javascript_vm.eventLoop().enqueueTaskConcurrent(task.concurrent_task.from(task, .manual_deinit)); } }; -- cgit v1.2.3