use zero copy improve string and byte convert - #525
Open
imxyb wants to merge 1 commit into
Open
Conversation
stevenh
requested changes
Oct 15, 2020
stevenh
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the PR, this seems like a risky change based on the comments I found here:
golang/go#25484
This refers to the fact this would be more easy when golang/go#19367 is merged so I think we should wait for that.
Collaborator
|
Looks like the proposal golang/go#53003 has been accepted recently so we can look to use those when they are implemented. |
Collaborator
|
I believe the compiler in go 1.21 is doing this optimisation by default as there no difference between func BenchmarkReplyHelpers(b *testing.B) {
c, err := dial()
require.NoError(b, err)
defer c.Close()
_, err = c.Do("SET", "k1", "1")
require.NoError(b, err)
b.Run("String", func(b *testing.B) {
reply, err := c.Do("GET", "k1")
require.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = redis.String(reply, err)
}
b.StopTimer()
// Outside the loop, so the compiler cannot optimize the function call away.
require.NoError(b, err)
})
b.Run("Int", func(b *testing.B) {
reply, err := c.Do("GET", "k1")
require.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = redis.String(reply, err)
}
b.StopTimer()
// Outside the loop, so the compiler cannot optimize the function call away.
require.NoError(b, err)
})
b.Run("Int64", func(b *testing.B) {
reply, err := c.Do("GET", "k1")
require.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = redis.Int64(reply, err)
}
b.StopTimer()
// Outside the loop, so the compiler cannot optimize the function call away.
require.NoError(b, err)
})
b.Run("Uint64", func(b *testing.B) {
reply, err := c.Do("GET", "k1")
require.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = redis.Uint64(reply, err)
}
b.StopTimer()
// Outside the loop, so the compiler cannot optimize the function call away.
require.NoError(b, err)
})
b.Run("Float64", func(b *testing.B) {
reply, err := c.Do("GET", "k1")
require.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = redis.Float64(reply, err)
}
b.StopTimer()
// Outside the loop, so the compiler cannot optimize the function call away.
require.NoError(b, err)
})
b.Run("Bool", func(b *testing.B) {
reply, err := c.Do("GET", "k1")
require.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = redis.Bool(reply, err)
}
b.StopTimer()
// Outside the loop, so the compiler cannot optimize the function call away.
require.NoError(b, err)
})
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bench result: