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

[vt/sqlparser] Use strings.Builder in compliantName #4470

Merged
merged 1 commit into from
Dec 19, 2018
Merged

[vt/sqlparser] Use strings.Builder in compliantName #4470

merged 1 commit into from
Dec 19, 2018

Conversation

LK4D4
Copy link
Contributor

@LK4D4 LK4D4 commented Dec 19, 2018

It halves allocations.
I would like to use it for Myprintf also very much, but I definitely need more research :)

@LK4D4 LK4D4 requested a review from sougou as a code owner December 19, 2018 02:04
Copy link
Contributor

@sougou sougou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Very nice! Any benchmarks?

@LK4D4
Copy link
Contributor Author

LK4D4 commented Dec 19, 2018

@sougou nope, nothing in sqlparser benchmarks shows any difference :)
But strings builder is basically bytes.Buffer which can be used only once because it uses unsafe trick to not allocate string on String():
https://golang.org/src/strings/builder.go?s=1379:1412#L36
It was made for such cases.

@LK4D4
Copy link
Contributor Author

LK4D4 commented Dec 19, 2018

@sougou
I wrote

+
+func BenchmarkCompliantName(b *testing.B) {
+       testString := ".ab"
+       for i := 0; i < b.N; i++ {
+               _ = NewColIdent(testString).CompliantName()
+               _ = NewTableIdent(testString).CompliantName()
+       }
+}

Results are:

benchmark                    old ns/op     new ns/op     delta
BenchmarkCompliantName-8     231           75.8          -67.19%

benchmark                    old allocs     new allocs     delta
BenchmarkCompliantName-8     4              2              -50.00%

benchmark                    old bytes     new bytes     delta
BenchmarkCompliantName-8     230           16            -93.04%

@sougou sougou merged commit b2b6db5 into vitessio:master Dec 19, 2018
@LK4D4 LK4D4 deleted the builder_names branch December 19, 2018 02:51
@slanning
Copy link
Contributor

Note that this requires go 1.10+
(1.9: "go/vt/sqlparser/ast.go:3694:10: undefined: strings.Builder";
https://golang.org/pkg/strings/#Builder )
bootstrap.sh only requires that go version doesn't fail, though some docs mention installing 1.11+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants