EfficientHashing
EfficientHashing 将 Vec3i(及其子类如 BlockPos)的哈希算法替换为一种具有极高抗碰撞性的算法,从而在几乎所有使用其哈希码的地方提升了性能。
抗碰撞性
我们可以通过一个简单的测试来证明这一点。该测试对 new BlockPos(-100, -20, -100) 到 new BlockPos(100, 50, 100)(包含边界)之间的所有 BlockPos 组合进行哈希处理,对象总数达到 2,800,000+。
原版算法总共生成了 194,571 个唯一的哈希码。这意味着至少 93% 的所有 BlockPos 哈希码都存在碰撞。
而 EfficientHashing 所使用的 PhiMix 算法总共生成了 2,868,471 个唯一的哈希码。这意味着每个唯一的 BlockPos 对象都获得了其独特的哈希码,且没有任何 BlockPos 哈希码发生碰撞。
| 唯一哈希码数 | 碰撞次数 | 碰撞率 | |
|---|---|---|---|
| Vanilla | 194,571 | 2,673,900 | 93.2% |
| EfficientHashing | 2,868,471 | 0 | 0% |
如果你好奇实际的测试代码,请参见:这里
高性能
基准测试时间:
Benchmark Mode Cnt Score Error Units
VecHashingBenchmark.mixin thrpt 5 47.012 ± 1.029 ops/s
VecHashingBenchmark.vanilla thrpt 5 49.326 ± 1.507 ops/s
PhiMix 的性能约为原始哈希算法的 95.3%。是的,它稍慢一些,但与其他哈希解决方案相比,这一性能差距相对微小,并且可以轻易被哈希抗碰撞性的显著提升所抵消。
如果你好奇实际的基准测试代码,请参见:这里
兼容原版
在原版的哈希算法中,如果你对 BlockPos/Vec3i 的“默认”实例(即 new BlockPos(0, 0, 0))进行哈希处理,生成的哈希码将是 0,这恰好也是整数的“默认”实例值。PhiMix 中也存在这种特殊行为,从而提供了最佳的原版兼容性。
EfficientHashing
EfficientHashing replaced hashing algorithm of Vec3i (and its subclasses like BlockPos) with one that's much much
more collision resistant, providing performance improvement in basically wherever its hashcode is used.
Collision Resistant
We can prove this by doing a simple test. Test is perform by hashing every combination of BlockPos between
new BlockPos(-100, -20, -100) and new BlockPos(100, 50, 100) (inclusive), with the total object count reaching
2,800,000+.
Vanilla algorithm produced 194,571 unique hashcode in total. This means that at least 93% of all BlockPos hashcode are colliding with each other.
And PhiMix, the algorithm used by EfficientHashing, produced 2868471 unique hashcode in total. This means that every unique BlockPos object gets its unique hashcode, and NONE of all BlockPos hashcode are colliding.
| Unique Hashcode | Collision | Collision Rate | |
|---|---|---|---|
| Vanilla | 194,571 | 2,673,900 | 93.2% |
| EfficientHashing | 2,868,471 | 0 | 0% |
If you're curious about the actual test code, see: here
Performant
Benchmark time:
Benchmark Mode Cnt Score Error Units
VecHashingBenchmark.mixin thrpt 5 47.012 ± 1.029 ops/s
VecHashingBenchmark.vanilla thrpt 5 49.326 ± 1.507 ops/s
PhiMix is about 95.3% the performance of original hashing algorithm. Yes, it's slower, but this performance gap is relatively tiny compared to other hashing solution, and can be easily outweighed by the significant improvement in hash collision resistance.
If you're curious about the actual benchmark code, see: here
Vanilla compatible
In vanilla hashing algorithm, if you hash the "default" instance of BlockPos/Vec3i, aka new BlockPos(0, 0, 0), the
produced hashcode will be 0, which happens to be the "default" instance of integer. This special behavior is also
present in PhiMix, providing the best possible vanilla compatibility.
下载 EfficientHashing
下载 EfficientHashing
下载 EfficientHashing
下载 EfficientHashing
下载 EfficientHashing
下载 EfficientHashing
下载 EfficientHashing
下载 EfficientHashing
下载 EfficientHashing
下载 EfficientHashing
Efficient Hashing 1.0.2
- 修复 Forge 启动问题
- 修复模组图标
Efficient Hashing 1.0.1
- 支持 26.1.2
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
评论 0
登录后参与评分
还没有评论,来抢沙发吧