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

feat performance: upgrade cespare/xxhash to v2; refactor Cache.storer.write() to accept a string key instead of []byte #25607

Open
philjb opened this issue Dec 2, 2024 · 0 comments

Comments

@philjb
Copy link
Contributor

philjb commented Dec 2, 2024

Tasks

  • upgrade cespare/xxhash from v1 to v2 which includes some performance changes (when working with the go complier) and assembly versions of Sum64
  • The Cache storer interface has a write method that wants a byte slice key, but the key is only ever read in all implementations. When engine.WriteMulti calls into the cache to write, it has a string key already but is converting it to a byte slice to do the write. This byte slice allocates when we don't need to if a string was used all the way down that call path. The ask is to change that to avoid unnecessary allocations. It will need a new getPartitionStringKey method like below. All the storer interface methods could be updated to use string keys instead of byte slices but the main value is in the write method as it is the most used.
func (r *ring) getPartitionStringKey(key string) *partition {
	return r.partitions[int(xxhash.Sum64String(key)%uint64(len(r.partitions)))]
}
@philjb philjb changed the title feat: upgrade cespare/xxhash to v2; refactor Cache.storer.write() to accept a string key instead of []byte feat performance: upgrade cespare/xxhash to v2; refactor Cache.storer.write() to accept a string key instead of []byte Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants