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

Use string builder to reduce allocations #6

Merged
merged 1 commit into from
Aug 20, 2022

Conversation

olivier403
Copy link
Contributor

Hello, this pr uses strings.Builder instead of append to reduce the number of memory allocations.

Unidecode on string "üñíCöDÈ" repeated n times, with append:

cpu: AMD Ryzen 5 5600X 6-Core Processor             
BenchmarkUnidecode/go-unidecode_1-12             3358656               328.9 ns/op           256 B/op          7 allocs/op
BenchmarkUnidecode/go-unidecode_10-12             491061              2354 ns/op            4240 B/op         29 allocs/op
BenchmarkUnidecode/go-unidecode_100-12             64015             18734 ns/op           31440 B/op        212 allocs/op
BenchmarkUnidecode/go-unidecode_1000-12             4491            242756 ns/op          521266 B/op       2019 allocs/op
BenchmarkUnidecode/go-unidecode_10000-12             337           3411895 ns/op         5713300 B/op      20028 allocs/op

with strings.Builder:

cpu: AMD Ryzen 5 5600X 6-Core Processor             
BenchmarkUnidecode/go-unidecode_1-12            17364760                70.24 ns/op            8 B/op          1 allocs/op
BenchmarkUnidecode/go-unidecode_10-12            1610168               757.2 ns/op           248 B/op          5 allocs/op
BenchmarkUnidecode/go-unidecode_100-12            170352              6377 ns/op            1912 B/op          8 allocs/op
BenchmarkUnidecode/go-unidecode_1000-12            17743             68894 ns/op           34296 B/op         15 allocs/op
BenchmarkUnidecode/go-unidecode_10000-12            1668            760811 ns/op          285432 B/op         22 allocs/op

@mozillazg mozillazg changed the base branch from master to develop August 20, 2022 01:09
Copy link
Owner

@mozillazg mozillazg left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks for your contribution!

@mozillazg mozillazg merged commit f013cbc into mozillazg:develop Aug 20, 2022
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.

2 participants