diff options
author | 2023-04-17 23:03:58 -0700 | |
---|---|---|
committer | 2023-04-17 23:03:58 -0700 | |
commit | af96e8fcdd08d9bd2e84e7e8cc7fc404d683b4cc (patch) | |
tree | 73653e0cbac2124d8b1f32a3bf4c51dca8edcc07 | |
parent | 9e1745ee1f5844e6ab89135e776552d2ad1ad684 (diff) | |
download | bun-af96e8fcdd08d9bd2e84e7e8cc7fc404d683b4cc.tar.gz bun-af96e8fcdd08d9bd2e84e7e8cc7fc404d683b4cc.tar.zst bun-af96e8fcdd08d9bd2e84e7e8cc7fc404d683b4cc.zip |
Remove spin loop in `bun build`
-rw-r--r-- | src/bun.js/event_loop.zig | 22 | ||||
-rw-r--r-- | src/bundler/bundle_v2.zig | 9 |
2 files changed, 16 insertions, 15 deletions
diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig index 35ba93eaa..cf0b046ec 100644 --- a/src/bun.js/event_loop.zig +++ b/src/bun.js/event_loop.zig @@ -763,20 +763,17 @@ pub const MiniEventLoop = struct { pub fn tick( this: *MiniEventLoop, context: *anyopaque, + comptime isDone: fn (*anyopaque) bool, ) void { - while (true) { - _ = this.tickConcurrentWithCount(); - while (this.tasks.readItem()) |task| { - task.run(context); + while (!isDone(context)) { + if (this.tickConcurrentWithCount() == 0 and this.tasks.count == 0) { + this.loop.num_polls += 1; + this.loop.tick(); + this.loop.num_polls -= 1; } - if (this.tickConcurrentWithCount() == 0) { - if (this.loop.active > 0 or this.loop.num_polls > 0) { - this.loop.run(); - continue; - } - - break; + while (this.tasks.readItem()) |task| { + task.run(context); } } } @@ -845,6 +842,7 @@ pub const AnyEventLoop = union(enum) { pub fn tick( this: *AnyEventLoop, context: *anyopaque, + comptime isDone: fn (*anyopaque) bool, ) void { switch (this.*) { .jsc => { @@ -852,7 +850,7 @@ pub const AnyEventLoop = union(enum) { this.jsc.autoTick(); }, .mini => { - this.mini.tick(context); + this.mini.tick(context, isDone); }, } } diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index ae381bcf7..3a6587f1b 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -315,10 +315,13 @@ pub const BundleV2 = struct { return visitor.reachable.toOwnedSlice(); } + fn isDone(ptr: *anyopaque) bool { + var this = bun.cast(*BundleV2, ptr); + return this.graph.parse_pending == 0; + } + pub fn waitForParse(this: *BundleV2) void { - while (this.graph.parse_pending > 0) { - this.loop().tick(this); - } + this.loop().tick(this, isDone); debug("Parsed {d} files, producing {d} ASTs", .{ this.graph.input_files.len, this.graph.ast.len }); } |