aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/event_loop.zig12
-rw-r--r--src/env_loader.zig7
2 files changed, 17 insertions, 2 deletions
diff --git a/src/bun.js/event_loop.zig b/src/bun.js/event_loop.zig
index 724839ebc..7f175a1a1 100644
--- a/src/bun.js/event_loop.zig
+++ b/src/bun.js/event_loop.zig
@@ -455,6 +455,7 @@ pub const GarbageCollectionController = struct {
gc_repeating_timer: *uws.Timer = undefined,
gc_timer_interval: i32 = 0,
gc_repeating_timer_fast: bool = true,
+ disabled: bool = false,
pub fn init(this: *GarbageCollectionController, vm: *VirtualMachine) void {
var actual = vm.event_loop_handle.?;
@@ -469,8 +470,12 @@ pub const GarbageCollectionController = struct {
}
} else |_| {}
}
- this.gc_repeating_timer.set(this, onGCRepeatingTimer, gc_timer_interval, gc_timer_interval);
this.gc_timer_interval = gc_timer_interval;
+
+ this.disabled = vm.bundler.env.has("BUN_GC_TIMER_DISABLE");
+
+ if (!this.disabled)
+ this.gc_repeating_timer.set(this, onGCRepeatingTimer, gc_timer_interval, gc_timer_interval);
}
pub fn scheduleGCTimer(this: *GarbageCollectionController) void {
@@ -484,6 +489,7 @@ pub const GarbageCollectionController = struct {
pub fn onGCTimer(timer: *uws.Timer) callconv(.C) void {
var this = timer.as(*GarbageCollectionController);
+ if (this.disabled) return;
this.gc_timer_state = .run_on_next_tick;
}
@@ -528,11 +534,12 @@ pub const GarbageCollectionController = struct {
}
pub fn processGCTimer(this: *GarbageCollectionController) void {
+ if (this.disabled) return;
var vm = this.bunVM().global.vm();
this.processGCTimerWithHeapSize(vm, vm.blockBytesAllocated());
}
- pub fn processGCTimerWithHeapSize(this: *GarbageCollectionController, vm: *JSC.VM, this_heap_size: usize) void {
+ fn processGCTimerWithHeapSize(this: *GarbageCollectionController, vm: *JSC.VM, this_heap_size: usize) void {
const prev = this.gc_last_heap_size;
switch (this.gc_timer_state) {
@@ -568,6 +575,7 @@ pub const GarbageCollectionController = struct {
}
pub fn performGC(this: *GarbageCollectionController) void {
+ if (this.disabled) return;
var vm = this.bunVM().global.vm();
vm.collectAsync();
this.gc_last_heap_size = vm.blockBytesAllocated();
diff --git a/src/env_loader.zig b/src/env_loader.zig
index 2d467371a..b8fa90d45 100644
--- a/src/env_loader.zig
+++ b/src/env_loader.zig
@@ -37,6 +37,13 @@ pub const Loader = struct {
const empty_string_value: string = "\"\"";
+ pub fn has(this: *const Loader, input: []const u8) bool {
+ const value = this.map.get(input) orelse return false;
+ if (value.len == 0) return false;
+
+ return !strings.eqlComptime(value, "\"\"") and !strings.eqlComptime(value, "''") and !strings.eqlComptime(value, "0") and !strings.eqlComptime(value, "false");
+ }
+
pub fn isProduction(this: *const Loader) bool {
const env = this.map.get("BUN_ENV") orelse this.map.get("NODE_ENV") orelse return false;
return strings.eqlComptime(env, "production");