-
Notifications
You must be signed in to change notification settings - Fork 18k
x/text/secure/precis: too many allocations #17423
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
Comments
CL https://golang.org/cl/31189 mentions this issue. |
Use SpanningTransfomers to avoid allocations if input doesn’t change. Next step is to add ASCII fast paths. Updates golang/go#17423 Change-Id: I8496e77f1e13912b8537a3e98fe0e898cb5bc975 Reviewed-on: https://go-review.googlesource.com/31189 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
CL https://golang.org/cl/33435 mentions this issue. |
benchmark old ns/op new ns/op delta BenchmarkAppend/UsernameCaseMapped/ASCII-4 526 85.6 -83.73% BenchmarkBytes/UsernameCaseMapped/ASCII-4 523 114 -78.20% BenchmarkString/UsernameCaseMapped/ASCII-4 593 146 -75.38% BenchmarkAppend/UsernameCasePreserved/ASCII-4 180 82.5 -54.17% BenchmarkBytes/UsernameCasePreserved/ASCII-4 214 110 -48.60% BenchmarkString/UsernameCasePreserved/ASCII-4 247 146 -40.89% BenchmarkAppend/FreeForm/ASCII-4 112 81.4 -27.32% BenchmarkBytes/FreeForm/ASCII-4 143 112 -21.68% BenchmarkString/FreeForm/ASCII-4 170 139 -18.24% BenchmarkAppend/OpaqueString/ASCII-4 242 208 -14.05% BenchmarkBytes/OpaqueString/ASCII-4 276 242 -12.32% BenchmarkString/OpaqueString/ASCII-4 305 270 -11.48% BenchmarkAppend/Nickname/ASCII-4 481 446 -7.28% BenchmarkString/Nickname/ASCII-4 548 512 -6.57% BenchmarkBytes/Nickname/ASCII-4 478 450 -5.86% BenchmarkBytes/OpaqueString/Arabic-4 334 324 -2.99% BenchmarkTransform/UsernameCaseMapped/Arabic-4 516 506 -1.94% BenchmarkString/FreeForm/Hangul-4 671 658 -1.94% BenchmarkBytes/OpaqueString/Hangul-4 760 775 +1.97% BenchmarkString/Nickname/Hangul-4 1016 1036 +1.97% … Updates golang/go#17423 Change-Id: Ia70335212f1089f280653c2b7bea9f769373ae1d Reviewed-on: https://go-review.googlesource.com/33435 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Now that @mpvl has added spanning transformers to reduce allocations and I've added an ASCII fast path to make things quicker in the all-ascii case, can this issue be marked as resolved, or are there any other big tasks remaining that should be tracked as part of this issue instead of having their own? |
Seems good to me. |
The x/text/secure/precis package allocates several times, even when there is literally no work to do. For a plain ASCII identifier, which is a very common case, it could return the original string, and discover cheaply that it can do so.
% cat x_test.go
package x
import (
"testing"
)
func TestPrecisMallocs(t *testing.T) {
t.Fatal(testing.AllocsPerRun(100, func() { precis.UsernameCasePreserved.String("helloworld") }))
}
% go test
--- FAIL: TestPrecisMallocs (0.00s)
x_test.go:10: 6
The text was updated successfully, but these errors were encountered: