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
net/url: optimization for calling URL.Query multiple times #37583
Comments
I'm planning to add a cache for the return value of method
type URL struct {
Scheme string
Opaque string // encoded opaque data
User *Userinfo // username and password information
Host string // host or host:port
Path string // path (relative paths may omit leading slash)
RawPath string // encoded path hint (see EscapedPath method)
ForceQuery bool // append a query ('?') even if RawQuery is empty
RawQuery string // encoded query values, without '?'
Fragment string // fragment for references, without '#'
lastRawQueryParsed string
lastQueryResult Values
}
|
Thanks for filing an issue and discussing a potential fix first. The It may not be viable to add unexported fields to the To have good performance, users can implement caching in their handlers if they need to use the result of q := req.URL.Query()
// ... use q many times Alternatively, // use req.FormValue() many times |
This is expected behavior. Computations are instantaneous on the Go playground and don't use up time. Read the Faking time section of the playground blog post. |
Thanks for the advice @dmitshur. Is it OK to close this issue? *TIL: |
Glad to hear it! Let's wait a few days to see if anyone else has more thoughts on this, but after that it should be fine to close. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
*I write the source code here instead of writing it in play.golang.org because on that environment the output was always
elapsed time: 0s
(no idea 🤷♂️️)What did you expect to see?
(or something under 1ms)What did you see instead?
The text was updated successfully, but these errors were encountered: