feat: add option for using custom hashers#12
Conversation
|
Thanks for working on this. I do not think this PR should merge yet. The main issue is that the new custom-hasher support is only fully wired through the non-sharded cache. In There is a second gap in the weighted implementation. I did run the full test suite on the PR branch, and everything passed, which is a good sign for existing behavior. The problem is that there do not seem to be any tests exercising the new custom-hasher paths themselves, so these incomplete integrations slip through. I would want to see the custom hasher actually used consistently, or the scope of the feature and docs narrowed so they match what is really implemented. This is an automated review by Swival (https://swival.dev) using only open-source models, with the goal of helping both the pull request author and the maintainers. |
Thanks for the quick review! You’re right, I’ll continue working on this. I think I’ll find the time tomorrow at the latest :) |
|
@jedisct1 I am already implementing the fixes as we speak. While i was looking through the codebase, I noticed that the |
|
I do not see a behavioral reason for Since I would treat that as a small non-blocking improvement, not one of the issues holding this PR back. So if you are already touching If you do touch it as part of this PR, I would just make sure the change stays narrowly scoped and does not distract from the custom-hasher fixes. |
|
Hi @jedisct1. I implemented the changes. I also noticed the following issue: Due to the sharding in sharded cache versions, eviction will sometimes occur even though the capacity specified in the constructor is sufficient in theory. this occurs due to how the cache distributes the capacity amongst the shards. For example, a cache with a capacity of ten and a number of shards of 16 will have a capacity of 1 for the first ten shards and a capacity of zero for the remaining shards. I think this is out of scope for this PR, but it would definitely be worth mentioning in the docs, or every shard should have this capacity. Giving the capacity to every shard would incur a lot of memory overhead though. There also seems to be a flaky test ( |
|
I do not think this should merge yet. The biggest remaining issue is that the weighted sharded variant still does not actually honor the There is also a test coverage gap around feature combinations. The new integration test file The new tests also do not currently prove that the sharded caches are using the supplied hasher for shard I ran the PR branch in a detached worktree. The default suite passed cleanly with |
|
@jedisct1 the failing test is unrelated to my PR in my opinion. It's caused by the issue i described in my previous comment |
|
Findings
Notes
Merge recommendation: not quite ready yet. Once the unconditional This is an automated review by Swival (https://swival.dev), using only open-source tooling. |
|
@jedisct1 i added a feature-gate for the import. Also, please look at my previous comment concerning the failing test. How would you like me to address this problem? |
|
Non-default features still break: |
|
@jedisct1 I had to add feature guards to the |
|
@jedisct1 could you please give this another review if you find the time? |
|
The feature-gating issue looks fixed now: On the flaky One remaining custom-hasher issue I still see is the So from my side, the remaining action items are:
After that, this looks very close. |
…ensure Sharded variants reuse the correct hasher.
Add custom hash builder support (
new_with_hasher)Adds a generic type parameter
S: BuildHasher(defaulting toRandomState) to all cache types.Each type now exposes a
new_with_hasher(...)constructor (andwith_shards_and_hasherfor sharded variants), allowing callers to plug in a custom hashing algorithm such asahashfor improved performance. The existingnew(...)constructors are unchanged and delegate to the new ones usingDefault::default(), so there are no breaking changes.Documentation and README updated with usage examples.