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: Put all $_SERVER vars into one function call. #1303

Merged
merged 10 commits into from
Jan 8, 2025

Conversation

AlliBalliBaba
Copy link
Collaborator

After seeing that Cgo call overhead from entersyscall and exitsyscall is not insignificant, I though we might as well go all the way...

With many Cgo Calls
flame

With one big ugly Cgo Call and the original REQUEST_URI not in the prepared env (~3.5% faster on Linux)
flame

9fqw2v

The PR also passes the original request uri directly instead of via the prepared env so the preparedEnv doesn't need to be copied on each request (I was confused where the original request uri was actually coming from).

cgi.go Outdated Show resolved Hide resolved
frankenphp.c Outdated Show resolved Hide resolved
@withinboredom
Copy link
Collaborator

My only issue with this is the loss of flexibility and cost of change. In other words, it locks us into a single way of doing things. Otherwise, it's a good idea.

@dunglas
Copy link
Owner

dunglas commented Jan 6, 2025

@withinboredom as it's purely internal, we can change that back when/if needed.

@@ -316,6 +314,7 @@ func (f FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ ca
documentRootOption,
frankenphp.WithRequestSplitPath(f.SplitPath),
frankenphp.WithRequestPreparedEnv(env),
frankenphp.WithOriginalRequest(&origReq),
Copy link
Owner

Choose a reason for hiding this comment

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

Can't we keep the previous strategy to not increase the public API surface?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll try passing this via context instead. Doing it via the prepared env requires copying and registering it on every request (and passing the request uri via environment is a bit confusing)

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, using the context is a good idea.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I realized that you actually can't pass via context between packages, so this would need to be in the public api

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think it's necessarily bad to have this in a public api since having a different 'actual' request uri is a key PHP behavior for any application using index files. We can also only pass the uri instead of the whole request.

If you still dislike that, we can also reset it back to be passed via env (feels hacky but minimizes the public api)

frankenphp.c Outdated Show resolved Hide resolved
@dunglas dunglas merged commit 2b7b3d1 into main Jan 8, 2025
55 checks passed
@dunglas dunglas deleted the perf/reduce-cgo-calls branch January 8, 2025 07:23
@dunglas
Copy link
Owner

dunglas commented Jan 8, 2025

Thank you!! Great work as usual.

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.

4 participants