aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/api/server.zig17
-rw-r--r--src/bun.js/javascript.zig1
-rw-r--r--src/bun.js/webcore/response.zig37
3 files changed, 8 insertions, 47 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 1af7a5e31..39e9a8046 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -527,6 +527,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
has_marked_complete: bool = false,
response_jsvalue: JSC.JSValue = JSC.JSValue.zero,
+ response_protected: bool = false,
response_ptr: ?*JSC.WebCore.Response = null,
blob: JSC.WebCore.Blob = JSC.WebCore.Blob{},
promise: ?*JSC.JSValue = null,
@@ -813,7 +814,10 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
}
if (!this.response_jsvalue.isEmpty()) {
- this.server.response_objects_pool.push(this.server.globalThis, this.response_jsvalue);
+ if (this.response_protected) {
+ this.response_jsvalue.unprotect();
+ this.response_protected = false;
+ }
this.response_jsvalue = JSC.JSValue.zero;
}
@@ -1824,7 +1828,6 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
vm: *JSC.VirtualMachine = undefined,
globalThis: *JSGlobalObject,
base_url_string_for_joining: string = "",
- response_objects_pool: JSC.WebCore.Response.Pool = JSC.WebCore.Response.Pool{},
config: ServerConfig = ServerConfig{},
pending_requests: usize = 0,
request_pool_allocator: std.mem.Allocator = undefined,
@@ -1913,12 +1916,6 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
}
pub fn deinit(this: *ThisServer) void {
- if (this.vm.response_objects_pool) |pool| {
- if (pool == &this.response_objects_pool) {
- this.vm.response_objects_pool = null;
- }
- }
-
this.app.destroy();
const allocator = this.allocator;
allocator.destroy(this);
@@ -2025,7 +2022,6 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
this.listener = socket;
const needs_post_handler = this.vm.uws_event_loop == null;
this.vm.uws_event_loop = uws.Loop.get();
- this.vm.response_objects_pool = &this.response_objects_pool;
this.listen_callback = JSC.AnyTask.New(ThisServer, run).init(this);
this.vm.eventLoop().enqueueTask(JSC.Task.init(&this.listen_callback));
if (needs_post_handler) {
@@ -2150,14 +2146,17 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
if (response_value.as(JSC.WebCore.Response)) |response| {
ctx.response_jsvalue = response_value;
ctx.response_jsvalue.ensureStillAlive();
+ ctx.response_protected = false;
switch (response.body.value) {
.Blob => |*blob| {
if (blob.needsToReadFile()) {
response_value.protect();
+ ctx.response_protected = true;
}
},
.Locked => {
response_value.protect();
+ ctx.response_protected = true;
},
else => {},
}
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index e52c662f5..fc1817b9b 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -346,7 +346,6 @@ pub const VirtualMachine = struct {
file_blobs: JSC.WebCore.Blob.Store.Map,
source_mappings: SavedSourceMap = undefined,
- response_objects_pool: ?*Response.Pool = null,
rare_data: ?*JSC.RareData = null,
poller: JSC.Poller = JSC.Poller{},
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index fb2ffe19c..2e6b73be1 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -46,43 +46,6 @@ const uws = @import("uws");
pub const Response = struct {
pub usingnamespace JSC.Codegen.JSResponse;
- pub const Pool = struct {
- response_objects_pool: [127]JSC.JSValue = undefined,
- response_objects_used: u8 = 0,
-
- pub fn get(this: *Pool, ptr: *Response) ?JSValue {
- if (comptime JSC.is_bindgen)
- unreachable;
- if (this.response_objects_used > 0) {
- var result = this.response_objects_pool[this.response_objects_used - 1];
- this.response_objects_used -= 1;
- if (Response.dangerouslySetPtr(result, ptr)) {
- return result;
- } else {
- JSC.C.JSValueUnprotect(VirtualMachine.vm.global.ref(), result.asObjectRef());
- }
- }
-
- return null;
- }
-
- pub fn push(this: *Pool, globalThis: *JSC.JSGlobalObject, object: JSC.JSValue) void {
- var remaining = this.response_objects_pool[@minimum(this.response_objects_used, this.response_objects_pool.len)..];
- if (remaining.len == 0) {
- JSC.C.JSValueUnprotect(globalThis.ref(), object.asObjectRef());
- return;
- }
-
- if (object.as(Response)) |resp| {
- _ = Response.dangerouslySetPtr(object, null);
-
- _ = resp.body.use();
- resp.finalize();
- remaining[0] = object;
- this.response_objects_used += 1;
- }
- }
- };
allocator: std.mem.Allocator,
body: Body,