-
Notifications
You must be signed in to change notification settings - Fork 47
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
perf(mangling): optimized the processing of initialisms #79
Conversation
c3d1f85
to
78a9375
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #79 +/- ##
==========================================
+ Coverage 85.45% 86.91% +1.45%
==========================================
Files 12 13 +1
Lines 1609 1842 +233
==========================================
+ Hits 1375 1601 +226
- Misses 202 208 +6
- Partials 32 33 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
integration test w/ go-swagger: go-swagger/go-swagger#3060 |
This PR significantly improves the performance of name mangling utilities (e.g. ToGoName, etc). The need for this occured while benchmarking go-swagger's CI suite: surprisingly, the topmost allocator was swag.ToGoName. It is the result of a dozen successive optimization passes driven by profiling. These functions now execute ~10x faster and need 100 times less memory allocations. See BENCHMARK.md Optimization techniques used to reduce allocations: * pointer -> value (everything was pointers: now everything is values) * interface -> struct with a Kind field * closure -> func * string to []byte: use unsafe conversion * string concatenation -> use bytes.Buffer (recyclable, unlike strings.Builder) * static values converted over and over again: pre-bake the conversions * var x []T -> make([]T, 0, heuristic size) * temporarily allocated values -> use pool to recycle previously allocated data items Optimization techniques used to reduce CPU: * read unicode rune -> short-circuit for single byte runes * map lookup -> func with switch statement * for i, v := range -> for i := range (minor impact) Signed-off-by: Frédéric BIDON <fredbi@yahoo.com>
0ba0453
to
5904b43
Compare
I've been testing this over the week with go-openapi/analysis, go-openapi/validate and go-swagger. |
This PR significantly improves the performance of name-mangling
utilities (e.g. ToGoName, etc).
The need for this occurred while benchmarking go-swagger's CI suite:
surprisingly, the topmost allocator was swag.ToGoName.
It is the result of a dozen successive optimization passes driven
by profiling.
These functions now execute ~10x faster and need 100 times less
memory allocations. See BENCHMARK.md
Optimization techniques used to reduce allocations:
strings.Builder)
allocated data items
Optimization techniques used to reduce CPU:
Signed-off-by: Frédéric BIDON fredbi@yahoo.com