-
Notifications
You must be signed in to change notification settings - Fork 14
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
martian/header: optimized ViaModifier implementation #974
Conversation
c2ef68e
to
49c5498
Compare
if v := req.Header.Get("Via"); v != "" { | ||
if m.hasLoop(v) { | ||
if via != "" { | ||
if strings.Contains(via, m.requestedBy+"-"+m.boundary) { |
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.
How about precomputing m.requestedBy+"-"+m.boundary
instead of concatenating on every modify?
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.
Sure.
LGTM. I feel that optimisations are correct, but it would be useful to have #676. |
- ViaModifier immutable - Remove regex - Remove splitting - Allocate single chunk of memory (strings.Builder) - Precompute tag - Precompute common http literals Fixes #924
49c5498
to
99c4d8e
Compare
@Choraden check the new implementation |
I'm on it we can wait and see |
Here we could have a microbenchmark |
That's true. |
|
benchstat old.txt new.txt goos: darwin goarch: arm64 pkg: github.com/saucelabs/forwarder/internal/martian/header cpu: Apple M1 Pro │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ ViaModifier 2299.0n ± 3% 154.3n ± 2% -93.29% (p=0.000 n=10) │ old.txt │ new.txt │ │ B/op │ B/op vs base │ ViaModifier 1440.0 ± 0% 160.0 ± 0% -88.89% (p=0.000 n=10) │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ ViaModifier 31.000 ± 0% 4.000 ± 0% -87.10% (p=0.000 n=10)
It was indeed slow |
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.
💪
No description provided.