Skip to content

Conversation

@rueian
Copy link
Collaborator

@rueian rueian commented Dec 16, 2022

This PR actually removes almost all RedisResult memory allocation while delegating to RedisMessage. The previous memory allocation behavior can be considered a bug.

Given the following benchmark:

func BenchmarkRueidisToString(b *testing.B) {
	client, err := rueidis.NewClient(rueidis.ClientOption{InitAddress: []string{"127.0.0.1:6379"}})
	if err != nil {
		panic(err)
	}
	defer client.Close()
	b.ReportAllocs()
	b.ResetTimer()
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			_, _ = client.Do(context.Background(), client.B().Get().Key("Key").Build()).ToString()
		}
	})
	b.StopTimer()
}

The old result is:

goos: darwin
goarch: arm64
BenchmarkRueidisToString
BenchmarkRueidisToString-10    	  385492	      3397 ns/op	     163 B/op	       2 allocs/op
PASS

The new result will be:

goos: darwin
goarch: arm64
BenchmarkRueidisToString
BenchmarkRueidisToString-10    	  386966	      3087 ns/op	       3 B/op	       0 allocs/op
PASS

@codecov
Copy link

codecov bot commented Dec 16, 2022

Codecov Report

Base: 96.19% // Head: 96.18% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (b39f995) compared to base (0758427).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #160      +/-   ##
==========================================
- Coverage   96.19%   96.18%   -0.01%     
==========================================
  Files          36       36              
  Lines       25333    25382      +49     
==========================================
+ Hits        24368    24414      +46     
- Misses        845      847       +2     
- Partials      120      121       +1     
Impacted Files Coverage Δ
message.go 100.00% <100.00%> (ø)
rueidislock/lock.go 99.53% <0.00%> (-0.47%) ⬇️
pipe.go 99.74% <0.00%> (-0.26%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rueian rueian force-pushed the reduce-delegate-allocation branch from 2ac5043 to 5d32787 Compare December 16, 2022 16:04
@rueian rueian force-pushed the reduce-delegate-allocation branch from 873a2fd to b39f995 Compare December 16, 2022 16:41
@rueian
Copy link
Collaborator Author

rueian commented Dec 16, 2022

Hi @FZambia,

It is never-ending work, but you probably will like this one: it reduces allocations.

@rueian rueian merged commit 877562f into main Dec 16, 2022
@FZambia
Copy link
Contributor

FZambia commented Dec 16, 2022

Oh no, re-measure everything 😿 This is an amazing improvement, thanks!

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