go/analysis/passes/modernize: disable BLoop analyzer
When b.N is used to benchmark very small workloads,
the suggestion to use b.Loop may result in an increased
overhead that skews benchmark results. Since we cannot
accurately identify such workloads, we unfortunately
should just disable the b.Loop modernizer entirely.
Fixes golang/go#74967
diff --git a/go/analysis/passes/modernize/modernize.go b/go/analysis/passes/modernize/modernize.go
index da988a7..27e8d58 100644
--- a/go/analysis/passes/modernize/modernize.go
+++ b/go/analysis/passes/modernize/modernize.go
@@ -34,7 +34,7 @@
var Suite = []*analysis.Analyzer{
AnyAnalyzer,
// AppendClippedAnalyzer, // not nil-preserving!
- BLoopAnalyzer,
+ // BLoopAnalyzer, // may skew benchmark results, see golang/go#74967
FmtAppendfAnalyzer,
ForVarAnalyzer,
MapsLoopAnalyzer,
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
should just disable the b.Loop modernizer entirely....entirely in the go fix suite.
We should probably mention both here and in gopls/internal/settings/analysis.go that it's ok to leave it enabled in gopls since it's interactive, and thus subject to programmer scrutiny.
This CL will need to be cherrypicked to the go1.26 release branch.
// BLoopAnalyzer, // may skew benchmark results, see golang/go#74967Let's update the bloop entry in doc.go to mention that its fix may change the performance of nanosecond-scale benchmarks and for this reason bloop is not enabled by default in the go fix suite.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
...entirely in the go fix suite.
We should probably mention both here and in gopls/internal/settings/analysis.go that it's ok to leave it enabled in gopls since it's interactive, and thus subject to programmer scrutiny.
This CL will need to be cherrypicked to the go1.26 release branch.
Thanks, will do.
// BLoopAnalyzer, // may skew benchmark results, see golang/go#74967Let's update the bloop entry in doc.go to mention that its fix may change the performance of nanosecond-scale benchmarks and for this reason bloop is not enabled by default in the go fix suite.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
| Code-Review | +2 |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
go/analysis/passes/modernize: disable BLoop analyzer
When b.N is used to benchmark very small workloads,
the suggestion to use b.Loop may result in an increased
overhead that skews benchmark results. Since we cannot
accurately identify such workloads, we unfortunately
should just disable the b.Loop modernizer in the "go
fix" suite.
We leave the modernize enabled in gopls because
it is interactive and programmers will scrutinize
the edits.
Fixes golang/go#74967
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
go/analysis/passes/modernize: disable BLoop analyzer
When b.N is used to benchmark very small workloads,
the suggestion to use b.Loop may result in an increased
overhead that skews benchmark results. Since we cannot
accurately identify such workloads, we unfortunately
should just disable the b.Loop modernizer in the "go
fix" suite.
We leave the modernize enabled in gopls because
it is interactive and programmers will scrutinize
the edits.
Fixes golang/go#74967
Change-Id: I011a167feb865fee6a61cf611aeecb70b285f255
Reviewed-on: https://go-review.googlesource.com/c/tools/+/731962
Commit-Queue: Alan Donovan <adon...@google.com>
Reviewed-by: Alan Donovan <adon...@google.com>
LUCI-TryBot-Result: Go LUCI <golang...@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Alan Donovan <adon...@google.com>
(cherry picked from commit 267fc6b81a168aa829f97c9209c2cacb503a56f2)
diff --git a/go/analysis/passes/modernize/doc.go b/go/analysis/passes/modernize/doc.go
index 45aed79..f1202c7 100644
--- a/go/analysis/passes/modernize/doc.go
+++ b/go/analysis/passes/modernize/doc.go
@@ -80,6 +80,8 @@
Caveats: The b.Loop() method is designed to prevent the compiler from
optimizing away the benchmark loop, which can occasionally result in
slower execution due to increased allocations in some specific cases.
+Since its fix may change the performance of nanosecond-scale benchmarks,
+bloop is disabled by default in the `go fix` analyzer suite; see golang/go#74967.
# Analyzer any
diff --git a/go/analysis/passes/modernize/modernize.go b/go/analysis/passes/modernize/modernize.go
index 013ce79..f09a2d2 100644
--- a/go/analysis/passes/modernize/modernize.go
+++ b/go/analysis/passes/modernize/modernize.go
@@ -34,7 +34,7 @@
var Suite = []*analysis.Analyzer{
AnyAnalyzer,
// AppendClippedAnalyzer, // not nil-preserving!
- BLoopAnalyzer,
+ // BLoopAnalyzer, // may skew benchmark results, see golang/go#74967
FmtAppendfAnalyzer,
ForVarAnalyzer,
MapsLoopAnalyzer,
diff --git a/gopls/doc/analyzers.md b/gopls/doc/analyzers.md
index ddb4a1e..05bd059 100644
--- a/gopls/doc/analyzers.md
+++ b/gopls/doc/analyzers.md
@@ -2952,7 +2952,7 @@
This change makes benchmark code more readable and also removes the need for manual timer control, so any preceding calls to b.StartTimer, b.StopTimer, or b.ResetTimer within the same function will also be removed.
-Caveats: The b.Loop() method is designed to prevent the compiler from optimizing away the benchmark loop, which can occasionally result in slower execution due to increased allocations in some specific cases.
+Caveats: The b.Loop() method is designed to prevent the compiler from optimizing away the benchmark loop, which can occasionally result in slower execution due to increased allocations in some specific cases. Since its fix may change the performance of nanosecond-scale benchmarks, bloop is disabled by default in the \`go fix\` analyzer suite; see golang/go#74967.
Default: on.
diff --git a/gopls/internal/doc/api.json b/gopls/internal/doc/api.json
index e4f7262..84cd42b 100644
--- a/gopls/internal/doc/api.json
+++ b/gopls/internal/doc/api.json
@@ -1384,7 +1384,7 @@
},
{
"Name": "\"bloop\"",
- "Doc": "replace for-range over b.N with b.Loop\n\nThe bloop analyzer suggests replacing benchmark loops of the form\n`for i := 0; i \u003c b.N; i++` or `for range b.N` with the more modern\n`for b.Loop()`, which was added in Go 1.24.\n\nThis change makes benchmark code more readable and also removes the need for\nmanual timer control, so any preceding calls to b.StartTimer, b.StopTimer,\nor b.ResetTimer within the same function will also be removed.\n\nCaveats: The b.Loop() method is designed to prevent the compiler from\noptimizing away the benchmark loop, which can occasionally result in\nslower execution due to increased allocations in some specific cases.",
+ "Doc": "replace for-range over b.N with b.Loop\n\nThe bloop analyzer suggests replacing benchmark loops of the form\n`for i := 0; i \u003c b.N; i++` or `for range b.N` with the more modern\n`for b.Loop()`, which was added in Go 1.24.\n\nThis change makes benchmark code more readable and also removes the need for\nmanual timer control, so any preceding calls to b.StartTimer, b.StopTimer,\nor b.ResetTimer within the same function will also be removed.\n\nCaveats: The b.Loop() method is designed to prevent the compiler from\noptimizing away the benchmark loop, which can occasionally result in\nslower execution due to increased allocations in some specific cases.\nSince its fix may change the performance of nanosecond-scale benchmarks,\nbloop is disabled by default in the `go fix` analyzer suite; see golang/go#74967.",
"Default": "true",
"Status": ""
},
@@ -3287,7 +3287,7 @@
},
{
"Name": "bloop",
- "Doc": "replace for-range over b.N with b.Loop\n\nThe bloop analyzer suggests replacing benchmark loops of the form\n`for i := 0; i \u003c b.N; i++` or `for range b.N` with the more modern\n`for b.Loop()`, which was added in Go 1.24.\n\nThis change makes benchmark code more readable and also removes the need for\nmanual timer control, so any preceding calls to b.StartTimer, b.StopTimer,\nor b.ResetTimer within the same function will also be removed.\n\nCaveats: The b.Loop() method is designed to prevent the compiler from\noptimizing away the benchmark loop, which can occasionally result in\nslower execution due to increased allocations in some specific cases.",
+ "Doc": "replace for-range over b.N with b.Loop\n\nThe bloop analyzer suggests replacing benchmark loops of the form\n`for i := 0; i \u003c b.N; i++` or `for range b.N` with the more modern\n`for b.Loop()`, which was added in Go 1.24.\n\nThis change makes benchmark code more readable and also removes the need for\nmanual timer control, so any preceding calls to b.StartTimer, b.StopTimer,\nor b.ResetTimer within the same function will also be removed.\n\nCaveats: The b.Loop() method is designed to prevent the compiler from\noptimizing away the benchmark loop, which can occasionally result in\nslower execution due to increased allocations in some specific cases.\nSince its fix may change the performance of nanosecond-scale benchmarks,\nbloop is disabled by default in the `go fix` analyzer suite; see golang/go#74967.",
"URL": "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/modernize#bloop",
"Default": true
},
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |