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(ext/http): optimize inferrable content-type responses #26424

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

littledivy
Copy link
Member

Skip manually setting header via op_http_set_response_header if Content-Type can be inferred from body. Optimizes the case for new Response(<string>)

--strace-ops in main:

[     1.726] op_http_wait                                       : Dispatched Async
[     1.726] op_http_set_response_header                        : Dispatched Fast
[     1.726] op_http_set_response_header                        : Completed Fast
[     1.726] op_http_set_response_body_text                     : Dispatched Fast
[     1.726] op_http_set_response_body_text                     : Completed Fast
[     1.726] op_run_microtasks                                  : Completed Fast

--strace-ops for this patch:

[     1.726] op_http_wait                                       : Dispatched Async
[     1.726] op_http_set_response_body_text                     : Dispatched Fast
[     1.726] op_http_set_response_body_text                     : Completed Fast
[     1.726] op_run_microtasks                                  : Completed Fast

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the behaviour of this code, and also changes the behaviour of Deno.serve with a response returned that was created like this.

> const resp = new Response("hello world")
undefined
> resp.headers
Headers { "content-type": "text/plain;charset=UTF-8" }
> resp.headers.delete("content-type")
undefined
> resp.headers
Headers {}

@littledivy
Copy link
Member Author

@lucacasonato Oh that's interesting, maybe we can disable optimization when delete("content-type"). Are there any other cases like this?

@lucacasonato
Copy link
Member

lucacasonato commented Oct 21, 2024

If I am reading your code correctly, resp.headers right after new Response("hello world") would be empty. We should fix that too (or I am misreading the code). I misread the code.

@lucacasonato
Copy link
Member

I can't think of other cases right now.

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.

2 participants