-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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: replace unsafe with the raw method for string to bytes conversion #3936
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3936 +/- ##
==========================================
- Coverage 99.21% 99.18% -0.03%
==========================================
Files 42 43 +1
Lines 3182 2709 -473
==========================================
- Hits 3157 2687 -470
+ Misses 17 12 -5
- Partials 8 10 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@appleboy I also saw this article, it's true for go 1.21. As of go 1.22 now, it's still true for bytes-to-string conversion, but it's wrong for string-to-bytes conversion. Here's the benchmark results they posted in the article (the author uses go 1.21.3):
Here's the benchmark results I get when I run it locally (I use go 1.22.2 which is the latest version):
Please check the difference on this row specifically:
After further digging into it, I found go1.22.0 introduced this performance improvement but cannot find it in their release notes or changelogs... As of go 1.22 now, string to bytes conversion using the standard way is also 0 memory allocation, and faster. Please take another look at my issue and PR @appleboy |
Issue references: #3935
For string to bytes conversion
Two points to make this change:
Benchmark result in: gin/internal/bytesconv/bytesconv_test.go: