Skip to content
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

x/text/secure/precis: too many allocations #17423

Closed
robpike opened this issue Oct 12, 2016 · 4 comments
Closed

x/text/secure/precis: too many allocations #17423

robpike opened this issue Oct 12, 2016 · 4 comments

Comments

@robpike
Copy link
Contributor

robpike commented Oct 12, 2016

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"

"golang.org/x/text/secure/precis"

)

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

@dsnet dsnet added this to the Unreleased milestone Oct 12, 2016
@gopherbot
Copy link

CL https://golang.org/cl/31189 mentions this issue.

gopherbot pushed a commit to golang/text that referenced this issue Oct 20, 2016
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>
@gopherbot
Copy link

CL https://golang.org/cl/33435 mentions this issue.

gopherbot pushed a commit to golang/text that referenced this issue Nov 29, 2016
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>
@SamWhited
Copy link
Member

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?

@robpike
Copy link
Contributor Author

robpike commented Dec 28, 2016

Seems good to me.

@robpike robpike closed this as completed Dec 28, 2016
@golang golang locked and limited conversation to collaborators Dec 28, 2017
@rsc rsc unassigned mpvl Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants