diff options
author | 2022-12-01 02:34:15 -0800 | |
---|---|---|
committer | 2022-12-01 02:34:15 -0800 | |
commit | bddf523ac9d201a1d15aa8b938b516aa1a6949aa (patch) | |
tree | f073b450e989954d7389ea4654bced3e96727d92 /src/bun.js/api/server.zig | |
parent | 1506a25198ce1c09d102c6a7a88ed24cc2a8be8a (diff) | |
download | bun-bddf523ac9d201a1d15aa8b938b516aa1a6949aa.tar.gz bun-bddf523ac9d201a1d15aa8b938b516aa1a6949aa.tar.zst bun-bddf523ac9d201a1d15aa8b938b516aa1a6949aa.zip |
Reduce memory usage in Bun.serve() by up to 3x (#1569)
* Update WebKit
* Use 5x less memory in Bun.serve()
* Update Dockerfile.devcontainer
* Update async-overhead.mjs
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/api/server.zig')
-rw-r--r-- | src/bun.js/api/server.zig | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index fb991481f..e2892f88f 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -4169,6 +4169,8 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { } pub fn onRequestComplete(this: *ThisServer) void { + this.vm.eventLoop().processGCTimer(); + this.pending_requests -= 1; this.deinitIfWeCan(); } @@ -4567,7 +4569,14 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { this.config.hostname; this.ref(); - this.vm.autoGarbageCollect(); + + // Starting up an HTTP server is a good time to GC + if (this.vm.aggressive_garbage_collection == .aggressive) { + this.vm.autoGarbageCollect(); + } else { + this.vm.eventLoop().performGC(); + } + this.app.listenWithConfig(*ThisServer, this, onListen, .{ .port = this.config.port, .host = host, |