Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(web): fast path for returning Response #850

Merged
merged 3 commits into from
Jul 25, 2024
Merged

perf(web): fast path for returning Response #850

merged 3 commits into from
Jul 25, 2024

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Jul 25, 2024

Normally when we return a value for h3, it tries to detect the content type and prepare a response/response-init. When users directly return a Response object (and have not preset any other headers or status/statusCode), we can go through a fast path optimization making handling %3 to %6 faster.


But there is another part in the story. When h3 is combined with other web framework handlers that always return a Response object, we were blindly creating another Response object because it was working based on merging.

By smarty reusing the same Response object, we can speed up to 2x (Bun) (%25 on Node) in performances.

image

This change also has the benefit that onBeforeResponse has access to the final prepared Response object instead of prepared ResponseInit

@pi0 pi0 self-assigned this Jul 25, 2024
@pi0 pi0 marked this pull request as ready for review July 25, 2024 11:03
@pi0 pi0 merged commit b337fe7 into main Jul 25, 2024
3 checks passed
@pi0 pi0 deleted the perf/fast-res branch July 25, 2024 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant