aHash icon indicating copy to clipboard operation
aHash copied to clipboard

Support specializing get_hash without nightly

Open dtolnay opened this issue 1 year ago • 6 comments

Submitting as an alternative to #239. Benchmarks:

Before:

RUSTFLAGS='-Ctarget-cpu=native' cargo bench --bench ahash
    aeshash/u8              time:   [994.20 ps 995.35 ps 996.54 ps]                        
    aeshash/u16             time:   [994.81 ps 995.50 ps 996.21 ps]                         
    aeshash/u32             time:   [1.0140 ns 1.0169 ns 1.0204 ns]                         
    aeshash/u64             time:   [988.77 ps 989.85 ps 991.07 ps]                         
    aeshash/u128            time:   [501.29 ps 502.12 ps 503.08 ps]                          
    aeshash/strings         time:   [57.541 ns 57.576 ns 57.615 ns]                            

cargo bench --bench ahash
    fallbackhash/u8         time:   [976.34 ps 977.16 ps 978.05 ps]                             
    fallbackhash/u16        time:   [982.23 ps 983.48 ps 984.79 ps]                              
    fallbackhash/u32        time:   [983.96 ps 986.30 ps 989.23 ps]                              
    fallbackhash/u64        time:   [976.09 ps 980.99 ps 987.61 ps]                              
    fallbackhash/u128       time:   [1.2632 ns 1.2644 ns 1.2657 ns]                               
    fallbackhash/strings    time:   [129.09 ns 129.21 ns 129.33 ns]                                 

RUSTFLAGS='-Zallow-features= -Ctarget-cpu=native' cargo bench --bench ahash
    aeshash/u8              time:   [551.31 ps 551.92 ps 552.62 ps]                        
    aeshash/u16             time:   [587.73 ps 588.50 ps 589.33 ps]                         
    aeshash/u32             time:   [548.83 ps 550.01 ps 551.29 ps]                         
    aeshash/u64             time:   [549.42 ps 550.84 ps 552.65 ps]                         
    aeshash/u128            time:   [557.69 ps 558.17 ps 558.70 ps]                          
    aeshash/strings         time:   [57.197 ns 57.271 ns 57.355 ns]                            

RUSTFLAGS='-Zallow-features=' cargo bench --bench ahash
    fallbackhash/u8         time:   [1.1932 ns 1.1941 ns 1.1951 ns]                             
    fallbackhash/u16        time:   [1.2140 ns 1.2161 ns 1.2190 ns]                              
    fallbackhash/u32        time:   [1.2145 ns 1.2160 ns 1.2176 ns]                              
    fallbackhash/u64        time:   [1.2148 ns 1.2194 ns 1.2247 ns]                              
    fallbackhash/u128       time:   [1.4800 ns 1.4820 ns 1.4842 ns]                               
    fallbackhash/strings    time:   [129.03 ns 129.26 ns 129.55 ns]                                 

After:

RUSTFLAGS='-Zallow-features= -Ctarget-cpu=native' cargo bench --bench ahash
    aeshash/u8              time:   [990.82 ps 991.44 ps 992.03 ps]                        
    aeshash/u16             time:   [986.98 ps 988.56 ps 990.37 ps]                         
    aeshash/u32             time:   [995.33 ps 996.65 ps 998.35 ps]                         
    aeshash/u64             time:   [987.58 ps 988.99 ps 990.64 ps]                         
    aeshash/u128            time:   [506.18 ps 507.51 ps 509.45 ps]                          
    aeshash/strings         time:   [57.803 ns 57.859 ns 57.923 ns]                            

RUSTFLAGS='-Zallow-features=' cargo bench --bench ahash
    fallbackhash/u8         time:   [973.12 ps 973.98 ps 974.93 ps]                             
    fallbackhash/u16        time:   [976.37 ps 977.22 ps 978.17 ps]                              
    fallbackhash/u32        time:   [984.10 ps 984.82 ps 985.56 ps]                              
    fallbackhash/u64        time:   [977.77 ps 978.66 ps 979.64 ps]                              
    fallbackhash/u128       time:   [1.2595 ns 1.2606 ns 1.2618 ns]                               
    fallbackhash/strings    time:   [129.86 ns 130.00 ns 130.18 ns]                                 

It's clear that we are now getting exactly the specialized behavior of both aeshash and fallbackhash, even without the use of unstable min_specialization.

dtolnay avatar Aug 17 '24 04:08 dtolnay

Retargeting this to the 0.9 pre-release branch.

tkaitchuck avatar Aug 22 '24 19:08 tkaitchuck

@tkaitchuck If only 0.9 is fixed, then the abandoned unfixed 0.8 version will cause the same kind of pain that the abandoned unfixed 0.7 version has caused when only 0.8 had a fix.

kornelski avatar Aug 29 '24 00:08 kornelski

I agree with https://github.com/tkaitchuck/aHash/pull/242#issuecomment-2316468766 — I was hoping to get this in an 0.8 patch.

dtolnay avatar Oct 19 '24 20:10 dtolnay

I want to pull the generic type from the type of the map and type the builder to it rather than use that parameter. The advantage of this is we don't depend on having an implementation for the dereferenced type.

tkaitchuck avatar Apr 24 '25 23:04 tkaitchuck

  • Rebased over #261

dtolnay avatar May 04 '25 07:05 dtolnay

  • Rebased over https://github.com/tkaitchuck/aHash/pull/269

dtolnay avatar May 06 '25 20:05 dtolnay