ctxlock: use safe implementation of keyify #1459
Open
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.
I noticed while trying to implement some examples of libindex that
.Index()
method will panic on an emptyclaircore.Manifest
. I tracked this down tokeyify
panicing when it receives an empty string as input. I didn't really try to figure out the exact bug here becausereflect.StringHeader
is marked as deprecated anyway, so I tried the following function:That seemed to fix the problem, but then I was curious if this caused a performance hit, so I ran
BenchmarkUncontended
between that implementation and the previous implementation. The results looked similiar. Since the safe implementation was there and ready for benchmarking, I figured I'd test it as well. Here are the results from the tests:safe benchmark
Results:
BenchmarkUncontended-10 742704 89153 ns/op 1256 B/op 17 allocs/op
old_unsafe benchmark
Results:
BenchmarkUncontended-10 818978 87649 ns/op 1256 B/op 17 allocs/op
new_unsafe benchmark
Results:
BenchmarkUncontended-10 776305 87822 ns/op 1256 B/op 17 allocs/op
It seems that all implementations have similar performance. Therefore, I propose we remove all unsafe implementations.
I've attached a patch with the changes required to run the benchmarks described above. I encourage reviewers to run them as well, especially folks who have non-darwin systems.
benchmarks.patch