aboutsummaryrefslogtreecommitdiff
path: root/src/bun_js.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-08-28 21:28:05 -0700
committerGravatar GitHub <noreply@github.com> 2022-08-28 21:28:05 -0700
commitc1734c6ec5ef709ee4126b3474c7bee0a377a1fa (patch)
tree097710a13a1d85228efadf6d57823bb3a4f1c011 /src/bun_js.zig
parentb2141a204fbc351a40467037138168aea23a6930 (diff)
downloadbun-c1734c6ec5ef709ee4126b3474c7bee0a377a1fa.tar.gz
bun-c1734c6ec5ef709ee4126b3474c7bee0a377a1fa.tar.zst
bun-c1734c6ec5ef709ee4126b3474c7bee0a377a1fa.zip
More reliable macOS event loop (#1166)
* More reliable macOS event loop * Reduce CPU usage of idling * Add another implementation * Add benchmark Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun_js.zig')
-rw-r--r--src/bun_js.zig20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/bun_js.zig b/src/bun_js.zig
index aad8e2a8b..bb5f458f3 100644
--- a/src/bun_js.zig
+++ b/src/bun_js.zig
@@ -135,17 +135,25 @@ pub const Run = struct {
this.vm.tick();
{
- var i: usize = 0;
+ var any = false;
while (this.vm.*.event_loop.pending_tasks_count.loadUnchecked() > 0 or this.vm.active_tasks > 0) {
this.vm.tick();
- i +%= 1;
-
- if (i > 0 and i % 100 == 0) {
- std.time.sleep(std.time.ns_per_ms);
+ any = true;
+ if (this.vm.active_tasks > 0) {
+ if (this.vm.event_loop.ready_tasks_count.load(.Monotonic) == 0) {
+ _ = this.vm.global.vm().runGC(false);
+
+ if (this.vm.event_loop.ready_tasks_count.load(.Monotonic) == 0 and
+ this.vm.active_tasks > 0)
+ {
+ this.vm.event_loop.ensureWaker();
+ _ = this.vm.event_loop.waker.?.wait() catch 0;
+ }
+ }
}
}
- if (i > 0) {
+ if (any) {
if (this.vm.log.msgs.items.len > 0) {
if (Output.enable_ansi_colors) {
this.vm.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), true) catch {};