Skip to content

perf: pass original url directly - #2813

Open
henderkes wants to merge 1 commit into
mainfrom
perf/pass-original-url-directly
Open

henderkes wants to merge 1 commit into
mainfrom
perf/pass-original-url-directly

Conversation

@henderkes

Copy link
Copy Markdown
Contributor

instead of copying the full original request, just pass the original uri through as a string

user-space instructions per request
ModeBeforeAfter
Regular206,790204,275
Worker183,131180,432

Comment thread server.go Outdated
Comment on lines +160 to +162
func (s *Server) ServeHTTPWithOriginalURI(responseWriter http.ResponseWriter, request *http.Request, originalURI string, opts ...RequestOption) error {
return s.serveHTTP(responseWriter, request, originalURI, opts...)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not sure if we want to create a new public method, I'll leave that up to you

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the method itself serves two purposes though: for one we can get rid of the request allocation, second it enables getting rid of the request options slice copy every request as a follow-up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not just introducing a new Request Option?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Primarily for the follow-up I intend. But let me see if I can work around that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, can work around it. Switched to request option instead.

@henderkes
henderkes requested a review from dunglas November 5, 2026 07:25
@henderkes
henderkes force-pushed the perf/pass-original-url-directly branch from 69f8a32 to 0bebc4b Compare November 5, 2026 08:06
@dunglas

dunglas commented Nov 5, 2026

Copy link
Copy Markdown
Member

Maybe could we deprecate WithOriginalRequest to hint library users about this performance improvement?

Comment thread requestoptions.go Outdated

// WithRequestOriginalURI sets REQUEST_URI to the original URI before rewrites.
// An empty URI falls back to the current request URL.
func WithRequestOriginalURI(originalURI string) RequestOption {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
func WithRequestOriginalURI(originalURI string) RequestOption {
func WithOriginalRequestURI(uri string) RequestOption {

?

Comment thread requestoptions.go Outdated

// WithRequestOriginalURI sets REQUEST_URI to the original URI before rewrites.
// An empty URI falls back to the current request URL.
func WithRequestOriginalURI(originalURI string) RequestOption {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd just call it WithRequestURI

@henderkes henderkes Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't be clear since that could be the rewritten one.

@AlliBalliBaba

Copy link
Copy Markdown
Contributor

Did WithOriginalRequest really copy the request? I thought it just read out the uri and put it into the context.

@henderkes

Copy link
Copy Markdown
Contributor Author

Did WithOriginalRequest really copy the request? I thought it just read out the uri and put it into the context.

You made me double check, and it's actually the closure that's returned that causes the heap copy. Might be acceptable to just take the string into a local and capture that in the closure, would be a 2 line change.

@henderkes
henderkes force-pushed the perf/pass-original-url-directly branch from 1a5717d to 876d31a Compare November 6, 2026 05:04

This branch has not been deployed

No deployments
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.

3 participants