-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
refactor: faster $_SERVER variables creation #303
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't wait to test this...
allocServerVariable(&cArr, fc.env, gatewayInterface, "GATEWAY_INTERFACE", "CGI/1.1") | ||
allocServerVariable(&cArr, fc.env, serverProtocol, "SERVER_PROTOCOL", request.Proto) | ||
allocServerVariable(&cArr, fc.env, serverSoftware, "SERVER_SOFTWARE", "FrankenPHP") | ||
allocServerVariable(&cArr, fc.env, httpHost, "HTTP_HOST", request.Host) // added here, since not always part of headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does request.Host
come from the headers, if it is set there? I know many WordPress installs typically set the site name from this variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More or less yes https://pkg.go.dev/net/http#Request.Host
frankenphp_register_known_variable("REQUEST_URI", SG(request_info).request_uri, track_vars_array,false); | ||
|
||
/* Known variables */ | ||
frankenphp_register_known_variable("CONTENT_LENGTH", known_variables[0], track_vars_array, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth using consts for the indices of known_variables
and then reusing them in allocServerVariable()
on the Go side. It'd help with maintaining and reviewing, but other than that, wouldn't do anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it will help maintenance to add macros, to be honest, but PR is welcome!
da1e7bf
to
8492aa9
Compare
This patch changes how $_SERVER variables are populated to minimize allocations.
Also, reduce the number of switches between C and Go.
According to the benchmark introduced in #298, this change improves memory usage by 38% compared to
main
, and from 78% compared to RC3.Benchmark:
Some string data are still copied from C to Go. I tried to avoid that by using
unsafe.StringData)(
but didn't manage to get something that works because it looks not possible to pin pointers returned byunsafe.StringData()