Skip to content

AES hash is significantly slower than fallback for short strings on Broadwell #66

@as-com

Description

@as-com

Tested on a Broadwell Xeon E5-2690 v4 with Rust Nightly (1.51, 2020-01-09):

  • "1": 3.07 ns vs. 1.90 ns
  • "123": 3.00 ns vs. 2.01 ns
  • "1234": 3.00 ns vs. 2.11 ns
  • "1234567": 2.99 ns vs 2.10 ns
  • "12345678": 2.05 ns vs. 2.09 ns

This performance difference is very noticeable in some macrobenchmarks that involve aHash-powered hashmaps. If this is an inherent limitation of the AES-powered hash, perhaps it would be nice to have a feature flag or some other argument to force the use of the fallback hash if the hashed values are known to be short.

Raw test results
aeshash/u8              time:   [883.26 ps 885.33 ps 887.31 ps]                        

aeshash/u16             time:   [848.89 ps 852.85 ps 856.76 ps]                         
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

aeshash/u32             time:   [837.57 ps 841.42 ps 845.60 ps]                         
Found 5 outliers among 100 measurements (5.00%)
  3 (3.00%) high mild
  2 (2.00%) high severe

aeshash/u64             time:   [844.28 ps 848.31 ps 852.62 ps]                         
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe

aeshash/u128            time:   [634.65 ps 637.45 ps 640.59 ps]                          
Found 7 outliers among 100 measurements (7.00%)
  5 (5.00%) high mild
  2 (2.00%) high severe

aeshash/string/"1"      time:   [3.0568 ns 3.0707 ns 3.0857 ns]                                
Found 6 outliers among 100 measurements (6.00%)
  6 (6.00%) high mild
aeshash/string/"123"    time:   [2.9733 ns 3.0039 ns 3.0427 ns]                                  
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) high mild
  2 (2.00%) high severe
aeshash/string/"1234"   time:   [2.9937 ns 3.0096 ns 3.0261 ns]                                   
aeshash/string/"1234567"                                                                             
                        time:   [2.9739 ns 2.9858 ns 2.9995 ns]
aeshash/string/"12345678"                                                                             
                        time:   [2.0422 ns 2.0526 ns 2.0634 ns]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
aeshash/string/"123456789012345"                                                                             
                        time:   [2.1141 ns 2.1215 ns 2.1289 ns]
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) low mild
  2 (2.00%) high mild
aeshash/string/"1234567890123456"                                                                             
                        time:   [2.0369 ns 2.0457 ns 2.0556 ns]
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) high mild
  3 (3.00%) high severe
aeshash/string/"123456789012345678901234"                                                                             
                        time:   [2.2794 ns 2.2919 ns 2.3055 ns]
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  3 (3.00%) high mild
aeshash/string/"123456789012345678901234567890123"                                                                             
                        time:   [3.6343 ns 3.6497 ns 3.6677 ns]
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
aeshash/string/"12345678901234567890123456789012345678901234567890123456789012345678"                                                                             
                        time:   [8.6159 ns 8.6649 ns 8.7177 ns]
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) high mild
  2 (2.00%) high severe
aeshash/string/"123456789012345678901234567890123456789012345678901234567890123456789012345678901234...                                                                             
                        time:   [11.947 ns 12.029 ns 12.107 ns]
Found 5 outliers among 100 measurements (5.00%)
  4 (4.00%) low mild
  1 (1.00%) high severe
aeshash/string/"123456789012345678901234567890123456789012345678901234567890123456789012345678901234... #2                                                                             
                        time:   [44.972 ns 45.239 ns 45.515 ns]
Found 5 outliers among 100 measurements (5.00%)
  4 (4.00%) high mild
  1 (1.00%) high severe
fallback/u8             time:   [888.06 ps 889.87 ps 891.68 ps]                         
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) low mild
  1 (1.00%) high mild

fallback/u16            time:   [881.25 ps 884.31 ps 888.02 ps]                          
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) low mild
  2 (2.00%) high severe

fallback/u32            time:   [888.11 ps 891.69 ps 895.86 ps]                          
Found 8 outliers among 100 measurements (8.00%)
  2 (2.00%) low mild
  1 (1.00%) high mild
  5 (5.00%) high severe

fallback/u64            time:   [881.68 ps 883.99 ps 886.34 ps]                          
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) high mild
  3 (3.00%) high severe

fallback/u128           time:   [681.99 ps 683.29 ps 684.65 ps]                           
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  2 (2.00%) high mild
  1 (1.00%) high severe

fallback/string/"1"     time:   [1.9006 ns 1.9042 ns 1.9079 ns]                                 
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe
fallback/string/"123"   time:   [2.0054 ns 2.0109 ns 2.0163 ns]                                   
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
fallback/string/"1234"  time:   [2.0983 ns 2.1073 ns 2.1166 ns]                                    
Found 5 outliers among 100 measurements (5.00%)
  2 (2.00%) high mild
  3 (3.00%) high severe
fallback/string/"1234567"                                                                             
                        time:   [2.0951 ns 2.1031 ns 2.1110 ns]
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe
fallback/string/"12345678"                                                                             
                        time:   [2.0800 ns 2.0892 ns 2.0982 ns]
fallback/string/"123456789012345"                                                                             
                        time:   [2.3176 ns 2.3222 ns 2.3268 ns]
Found 6 outliers among 100 measurements (6.00%)
  3 (3.00%) low mild
  2 (2.00%) high mild
  1 (1.00%) high severe
fallback/string/"1234567890123456"                                                                             
                        time:   [2.3022 ns 2.3065 ns 2.3108 ns]
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe
fallback/string/"123456789012345678901234"                                                                             
                        time:   [3.5435 ns 3.5927 ns 3.6562 ns]
Found 7 outliers among 100 measurements (7.00%)
  1 (1.00%) high mild
  6 (6.00%) high severe
fallback/string/"123456789012345678901234567890123"                                                                             
                        time:   [4.8958 ns 4.9083 ns 4.9210 ns]
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe
fallback/string/"12345678901234567890123456789012345678901234567890123456789012345678"                                                                             
                        time:   [7.5150 ns 7.5410 ns 7.5667 ns]
fallback/string/"12345678901234567890123456789012345678901234567890123456789012345678901234567890123...                                                                             
                        time:   [12.932 ns 12.951 ns 12.972 ns]
Found 5 outliers among 100 measurements (5.00%)
  4 (4.00%) high mild
  1 (1.00%) high severe
fallback/string/"12345678901234567890123456789012345678901234567890123456789012345678901234567890123... #2                                                                            
                        time:   [98.567 ns 98.730 ns 98.885 ns]
Found 2 outliers among 100 measurements (2.00%)
  2 (2.00%) high severe

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions