aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-19 03:51:01 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-19 03:51:01 -0700
commit9222a5d37612a9c0e49bdc28c8e87f7149fafc63 (patch)
treea4f7db49dac9548264e07fa5fe1a6e6c0f605a53 /src/bun.js
parent0a0f8ff41c075ddc4838badc2e3f9f786db6a799 (diff)
downloadbun-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.zig17
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();
}