-
-
Notifications
You must be signed in to change notification settings - Fork 2k
π perf: Inline Request state wrappers #3827
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d29c495
π perf: inline Request state wrappers to cut GC scan (~4% faster requβ¦
arturmelanchyk 4d85de4
fix lint
arturmelanchyk f914a20
Update client/request.go
arturmelanchyk 7c21238
Update client/request.go
arturmelanchyk 3ee01ab
Update client/request_bench_test.go
arturmelanchyk 646f3a2
Update client/request_bench_test.go
arturmelanchyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package client | ||
|
|
||
| import ( | ||
| "runtime" | ||
| "runtime/metrics" | ||
| "strconv" | ||
| "testing" | ||
| ) | ||
|
|
||
| // BenchmarkRequestHeapScan measures how much heap memory the GC needs to scan | ||
| // when a batch of requests is created and released. | ||
| func BenchmarkRequestHeapScan(b *testing.B) { | ||
| samples := []metrics.Sample{ | ||
| {Name: "/gc/scan/heap:bytes"}, | ||
| {Name: "/gc/scan/total:bytes"}, | ||
| } | ||
|
|
||
| b.ReportAllocs() | ||
| b.StopTimer() | ||
| b.ResetTimer() | ||
|
|
||
| const batchSize = 512 | ||
| var totalScanHeap, totalScanAll uint64 | ||
| for i := 0; i < b.N; i++ { | ||
| reqs := make([]*Request, batchSize) | ||
| // revive:disable-next-line:call-to-gc // Ensure consistent heap state before measuring scan metrics | ||
| runtime.GC() | ||
| metrics.Read(samples) | ||
| startScanHeap := samples[0].Value.Uint64() | ||
| startScanAll := samples[1].Value.Uint64() | ||
|
|
||
| b.StartTimer() | ||
| for j := range reqs { | ||
| req := AcquireRequest() | ||
| req.SetHeader("X-Benchmark", "value") | ||
| req.SetCookie("session", strconv.Itoa(j)) | ||
| req.SetPathParam("id", strconv.Itoa(j)) | ||
| req.SetParam("page", strconv.Itoa(j)) | ||
| reqs[j] = req | ||
| } | ||
| b.StopTimer() | ||
|
|
||
| // revive:disable-next-line:call-to-gc // Force GC to capture post-benchmark scan metrics | ||
| runtime.GC() | ||
| metrics.Read(samples) | ||
| totalScanHeap += samples[0].Value.Uint64() - startScanHeap | ||
| totalScanAll += samples[1].Value.Uint64() - startScanAll | ||
|
|
||
| for _, req := range reqs { | ||
| ReleaseRequest(req) | ||
| } | ||
| } | ||
|
|
||
| if b.N > 0 { | ||
| b.ReportMetric(float64(totalScanHeap)/float64(b.N), "scan-bytes-heap/op") | ||
| b.ReportMetric(float64(totalScanAll)/float64(b.N), "scan-bytes-total/op") | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.