diff options
author | 2022-08-19 03:51:01 -0700 | |
---|---|---|
committer | 2022-08-19 03:51:01 -0700 | |
commit | 9222a5d37612a9c0e49bdc28c8e87f7149fafc63 (patch) | |
tree | a4f7db49dac9548264e07fa5fe1a6e6c0f605a53 /src/bun.js | |
parent | 0a0f8ff41c075ddc4838badc2e3f9f786db6a799 (diff) | |
download | bun-9222a5d37612a9c0e49bdc28c8e87f7149fafc63.tar.gz bun-9222a5d37612a9c0e49bdc28c8e87f7149fafc63.tar.zst bun-9222a5d37612a9c0e49bdc28c8e87f7149fafc63.zip |
2x faster `Bun.serve` with async function handlers
Diffstat (limited to 'src/bun.js')
-rw-r--r-- | src/bun.js/api/server.zig | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 4686c4a80..80565e84b 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -1481,11 +1481,20 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp } pub fn doRenderBlob(this: *RequestContext) void { - if (this.has_abort_handler) - this.resp.runCorkedWithType(*RequestContext, renderMetadata, this) - else - this.renderMetadata(); + // We are not corked + // The body is small + // Faster to do the memcpy than to do the two network calls + // We are not streaming + // This is an important performance optimization + if (this.has_abort_handler and this.blob.sharedView().len < 16384 - 1024) { + this.resp.runCorkedWithType(*RequestContext, doRenderBlobCorked, this); + } else { + this.doRenderBlobCorked(); + } + } + pub fn doRenderBlobCorked(this: *RequestContext) void { + this.renderMetadata(); this.renderBytes(); } |