Re: [PATCH] hash: add fast paths for common key sizes and new fast hash functions
From: Florian Westphal
Date: Sun Mar 15 2026 - 04:20:31 EST
Aaryan Bansal <aaryan.bansal.dev@xxxxxxxxx> wrote:
> Add optimized fast paths to jhash() and jhash2() for common key sizes
> (4, 8, 12 bytes) to bypass switch statement overhead. These fast paths
> use direct word reads instead of byte-by-byte processing.
>
> Also add new specialized hash functions for integer keys:
> - jhash_int(): Fast hash for single 32-bit integers (~3x faster)
> - jhash_int_2words(): Fast hash for two 32-bit integers
> - jhash_int_3words(): Fast hash for three 32-bit integers (e.g., IPv3 tuples)
> - jhash_mix32(): Ultra-fast hash for single integers
> - jhash_mix32_fast(): Minimal hash for extreme speed
>
> These are useful for in-kernel hash tables where maximum performance
> is critical and reduced hash quality is acceptable.
>
> Measured speedup on typical workloads:
> - jhash 4-byte keys: ~1.1x
> - jhash 8-byte keys: ~1.4x
> - jhash 12-byte keys: ~1.4x
> - jhash_int for single integers: ~3x
I won't merge a patch that adds functionality with no users.
Also, there already are helpers that do this
(jhash_1word, jhash_2words, jhash_3words).