Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ast: hash containers on insert/update #4367

Merged
merged 2 commits into from
Feb 21, 2022

Conversation

srenatus
Copy link
Contributor

@srenatus srenatus commented Feb 18, 2022

With this change, we'll calculate hashes as soon as we create or update arrays/sets/objects. This way, we avoid the race detected in #4345 when using PrepareForEval.

❓ Any catastrophic consequences I haven't foreseen?

Fixes #4345.

@srenatus srenatus marked this pull request as ready for review February 18, 2022 10:26
ast/term.go Outdated Show resolved Hide resolved
koponen-styra
koponen-styra previously approved these changes Feb 19, 2022
Copy link
Contributor

@koponen-styra koponen-styra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I do remember being concerned at some point about the cost of doing all the hashing proactively but I would expect we never construct these containers unless we actually compare them with high probability. Did you see any significant change in benchmarks? Either way, computing the hashes within functions mutating the containers seems cleaner design that making making the hashing after mutation concurrent safe.

This allows us to use the Hashes for comparisons, too, since they're
cheaply available all the time.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
@srenatus
Copy link
Contributor Author

I'm about to get this merged. Benchmarking ast, pr (new) against main (old), we find (benchstat):

name                                         old time/op    new time/op    delta
RewriteDynamics/1-16                            199ns ± 2%     215ns ± 2%   +8.42%  (p=0.008 n=5+5)
RewriteDynamics/10-16                          1.99µs ±12%    2.24µs ± 4%  +12.77%  (p=0.032 n=5+5)
RewriteDynamics/100-16                         18.6µs ± 2%    22.8µs ± 2%  +22.57%  (p=0.008 n=5+5)
RewriteDynamics/1000-16                         189µs ± 2%     230µs ± 1%  +21.17%  (p=0.008 n=5+5)
RewriteDynamics/10000-16                       2.09ms ± 3%    2.51ms ± 3%  +19.95%  (p=0.008 n=5+5)
RewriteDynamics/100000-16                      29.8ms ± 2%    34.0ms ± 2%  +14.33%  (p=0.008 n=5+5)
ParseModuleRulesBase/1-16                      17.9µs ± 1%    17.9µs ± 1%     ~     (p=1.000 n=5+5)
ParseModuleRulesBase/10-16                     52.5µs ± 1%    54.3µs ± 1%   +3.43%  (p=0.008 n=5+5)
ParseModuleRulesBase/100-16                     386µs ± 1%     388µs ± 1%     ~     (p=0.056 n=5+5)
ParseModuleRulesBase/1000-16                   3.76ms ± 0%    3.84ms ± 4%     ~     (p=0.690 n=5+5)
ParseStatementBasicCall-16                     15.8µs ± 1%    15.8µs ± 5%     ~     (p=0.690 n=5+5)
ParseStatementMixedJSON-16                      139µs ± 7%     136µs ± 1%     ~     (p=0.690 n=5+5)
ParseStatementSimpleArray/1-16                 16.6µs ±10%    14.9µs ± 1%  -10.16%  (p=0.032 n=5+5)
ParseStatementSimpleArray/10-16                25.6µs ± 3%    24.3µs ± 2%   -4.79%  (p=0.008 n=5+5)
ParseStatementSimpleArray/100-16                118µs ± 4%     113µs ± 2%   -4.36%  (p=0.016 n=5+5)
ParseStatementSimpleArray/1000-16              1.01ms ± 1%    0.97ms ± 1%   -3.14%  (p=0.008 n=5+5)
ParseStatementNestedObjects/1x1-16             17.2µs ± 2%    16.2µs ± 1%   -5.77%  (p=0.008 n=5+5)
ParseStatementNestedObjects/5x1-16             24.9µs ± 1%    24.7µs ± 1%     ~     (p=0.087 n=5+5)
ParseStatementNestedObjects/10x1-16            37.3µs ± 2%    36.1µs ± 2%   -3.02%  (p=0.016 n=5+5)
ParseStatementNestedObjects/1x5-16             24.2µs ± 2%    23.5µs ± 1%   -2.94%  (p=0.008 n=5+5)
ParseStatementNestedObjects/1x10-16            32.4µs ± 4%    30.8µs ± 2%   -4.94%  (p=0.016 n=5+5)
ParseStatementNestedObjects/5x5-16             8.53ms ± 4%    8.12ms ± 1%   -4.81%  (p=0.008 n=5+5)
ParseStatementNestedObjectsOrSets/1-16         18.1µs ± 8%    17.4µs ± 1%     ~     (p=0.222 n=5+5)
ParseStatementNestedObjectsOrSets/5-16         31.9µs ± 4%    30.2µs ± 5%   -5.28%  (p=0.032 n=5+5)
ParseStatementNestedObjectsOrSets/10-16        47.9µs ± 6%    45.8µs ± 2%     ~     (p=0.095 n=5+5)
ParseStatementNestedObjectsOrSets/15-16        63.2µs ± 2%    62.6µs ± 0%     ~     (p=0.151 n=5+5)
ParseStatementNestedObjectsOrSets/20-16        82.4µs ± 8%    79.9µs ± 2%     ~     (p=0.690 n=5+5)
ParseBasicABACModule-16                        79.0µs ± 4%    72.6µs ± 1%   -8.09%  (p=0.008 n=5+5)
ObjectLookup/5-16                              21.0ns ±11%    19.5ns ± 1%     ~     (p=0.095 n=5+5)
ObjectLookup/50-16                             27.8ns ± 7%    26.9ns ± 9%     ~     (p=0.548 n=5+5)
ObjectLookup/500-16                            25.8ns ± 4%    25.4ns ± 5%     ~     (p=0.421 n=5+5)
ObjectLookup/5000-16                           23.8ns ± 3%    24.9ns ± 6%     ~     (p=0.222 n=5+5)
SetIntersection/5-16                           1.03µs ± 1%    1.02µs ± 1%   -1.31%  (p=0.032 n=5+5)
SetIntersection/50-16                          14.5µs ± 4%    14.3µs ± 2%     ~     (p=0.421 n=5+5)
SetIntersection/500-16                          210µs ± 2%     205µs ± 3%     ~     (p=0.056 n=5+5)
SetIntersection/5000-16                        3.09ms ± 5%    2.96ms ± 2%     ~     (p=0.056 n=5+5)
SetIntersectionDifferentSize/4-16               898ns ± 1%     870ns ± 3%     ~     (p=0.056 n=5+5)
SetIntersectionDifferentSize/50-16              939ns ± 3%     954ns ± 2%     ~     (p=0.310 n=5+5)
SetIntersectionDifferentSize/500-16             917ns ± 4%     892ns ± 6%     ~     (p=0.095 n=5+5)
SetIntersectionDifferentSize/5000-16            934ns ± 3%     894ns ± 2%   -4.30%  (p=0.008 n=5+5)
SetMembership/5-16                             47.7ns ± 3%    41.5ns ± 1%  -12.92%  (p=0.008 n=5+5)
SetMembership/50-16                            58.6ns ± 5%    50.3ns ± 4%  -14.27%  (p=0.008 n=5+5)
SetMembership/500-16                           61.1ns ± 5%    52.7ns ± 2%  -13.67%  (p=0.008 n=5+5)
SetMembership/5000-16                          66.9ns ± 2%    58.1ns ± 5%  -13.19%  (p=0.008 n=5+5)
TermHashing/10-16                              8.51ns ± 1%    7.80ns ± 3%   -8.35%  (p=0.008 n=5+5)
TermHashing/100-16                             17.4ns ± 4%    16.7ns ± 2%   -4.38%  (p=0.024 n=5+5)
TermHashing/1000-16                            72.9ns ± 3%    67.3ns ± 1%   -7.78%  (p=0.008 n=5+5)
ObjectString/5/String()-16                      499ns ± 2%     486ns ± 1%   -2.66%  (p=0.032 n=5+5)
ObjectString/5/json.Marshal-16                 1.21µs ± 3%    1.14µs ± 0%   -5.30%  (p=0.008 n=5+5)
ObjectString/50/String()-16                    4.28µs ± 2%    4.08µs ± 1%   -4.81%  (p=0.008 n=5+5)
ObjectString/50/json.Marshal-16                11.6µs ± 3%    11.4µs ± 3%     ~     (p=0.421 n=5+5)
ObjectString/500/String()-16                   50.8µs ± 2%    50.9µs ± 5%     ~     (p=0.690 n=5+5)
ObjectString/500/json.Marshal-16                136µs ± 3%     138µs ± 2%     ~     (p=0.151 n=5+5)
ObjectString/5000/String()-16                   583µs ± 3%     553µs ± 1%   -5.09%  (p=0.008 n=5+5)
ObjectString/5000/json.Marshal-16              1.73ms ± 3%    1.64ms ± 1%   -5.21%  (p=0.008 n=5+5)
ObjectConstruction/shuffled_keys/5-16          1.77µs ± 3%    1.83µs ± 1%   +3.56%  (p=0.024 n=5+5)
ObjectConstruction/shuffled_keys/50-16         24.4µs ± 2%    24.7µs ± 3%     ~     (p=0.421 n=5+5)
ObjectConstruction/shuffled_keys/500-16         353µs ± 1%     350µs ± 1%     ~     (p=0.151 n=5+5)
ObjectConstruction/shuffled_keys/5000-16       5.09ms ± 2%    5.00ms ± 1%     ~     (p=0.095 n=5+5)
ObjectConstruction/shuffled_keys/50000-16       162ms ± 5%     154ms ± 7%     ~     (p=0.056 n=5+5)
ObjectConstruction/increasing_keys/5-16        1.81µs ± 2%    1.82µs ± 2%     ~     (p=0.421 n=5+5)
ObjectConstruction/increasing_keys/50-16       23.1µs ± 6%    22.7µs ± 1%     ~     (p=0.690 n=5+5)
ObjectConstruction/increasing_keys/500-16       323µs ± 2%     315µs ± 1%   -2.26%  (p=0.016 n=5+5)
ObjectConstruction/increasing_keys/5000-16     4.06ms ± 4%    3.93ms ± 2%   -2.99%  (p=0.032 n=5+5)
ObjectConstruction/increasing_keys/50000-16    51.6ms ± 6%    48.1ms ± 1%   -6.89%  (p=0.008 n=5+5)
ArrayString/5/String()-16                       463ns ± 3%     401ns ± 1%  -13.31%  (p=0.008 n=5+5)
ArrayString/5/json.Marshal-16                   262ns ± 4%     248ns ± 1%   -5.30%  (p=0.016 n=5+5)
ArrayString/50/String()-16                     4.18µs ± 5%    3.74µs ± 2%  -10.62%  (p=0.008 n=5+5)
ArrayString/50/json.Marshal-16                 1.38µs ± 5%    1.26µs ± 1%   -8.83%  (p=0.008 n=5+5)
ArrayString/500/String()-16                    45.8µs ± 3%    41.9µs ± 2%   -8.39%  (p=0.008 n=5+5)
ArrayString/500/json.Marshal-16                12.7µs ± 5%    11.7µs ± 1%   -7.58%  (p=0.008 n=5+5)
ArrayString/5000/String()-16                    407µs ± 4%     384µs ± 2%   -5.70%  (p=0.008 n=5+5)
ArrayString/5000/json.Marshal-16                127µs ± 3%     123µs ± 1%     ~     (p=0.095 n=5+5)
SetString/5/String()-16                        81.9ns ± 2%    80.3ns ± 1%     ~     (p=0.095 n=5+5)
SetString/50/String()-16                        536ns ± 6%     515ns ± 1%   -3.83%  (p=0.008 n=5+5)
SetString/500/String()-16                      5.22µs ± 5%    5.01µs ± 0%   -3.93%  (p=0.008 n=5+5)
SetString/5000/String()-16                     59.8µs ± 2%    60.7µs ± 2%     ~     (p=0.690 n=5+5)

name                                         old alloc/op   new alloc/op   delta
RewriteDynamics/1-16                            24.0B ± 0%     24.0B ± 0%     ~     (all equal)
RewriteDynamics/10-16                            240B ± 0%      240B ± 0%     ~     (all equal)
RewriteDynamics/100-16                         2.40kB ± 0%    2.40kB ± 0%     ~     (all equal)
RewriteDynamics/1000-16                        24.0kB ± 0%    24.0kB ± 0%     ~     (all equal)
RewriteDynamics/10000-16                        240kB ± 0%     240kB ± 0%     ~     (all equal)
RewriteDynamics/100000-16                      2.40MB ± 0%    2.40MB ± 0%     ~     (all equal)
ParseModuleRulesBase/1-16                      8.13kB ± 0%    8.13kB ± 0%     ~     (all equal)
ParseModuleRulesBase/10-16                     39.4kB ± 0%    39.4kB ± 0%     ~     (p=0.556 n=5+4)
ParseModuleRulesBase/100-16                     358kB ± 0%     358kB ± 0%     ~     (p=1.000 n=5+5)
ParseModuleRulesBase/1000-16                   3.59MB ± 0%    3.59MB ± 0%     ~     (p=0.881 n=5+5)
ParseStatementBasicCall-16                     6.69kB ± 0%    6.69kB ± 0%     ~     (all equal)
ParseStatementMixedJSON-16                      104kB ± 0%     104kB ± 0%   +0.03%  (p=0.016 n=4+5)
ParseStatementSimpleArray/1-16                 6.56kB ± 0%    6.59kB ± 0%   +0.49%  (p=0.016 n=4+5)
ParseStatementSimpleArray/10-16                13.7kB ± 0%    13.8kB ± 0%   +0.70%  (p=0.016 n=4+5)
ParseStatementSimpleArray/100-16               88.0kB ± 0%    88.9kB ± 0%   +1.04%  (p=0.008 n=5+5)
ParseStatementSimpleArray/1000-16               857kB ± 0%     865kB ± 0%   +0.96%  (p=0.008 n=5+5)
ParseStatementNestedObjects/1x1-16             7.71kB ± 0%    7.71kB ± 0%     ~     (all equal)
ParseStatementNestedObjects/5x1-16             14.2kB ± 0%    14.2kB ± 0%     ~     (p=1.000 n=5+5)
ParseStatementNestedObjects/10x1-16            22.4kB ± 0%    22.4kB ± 0%     ~     (p=0.968 n=5+4)
ParseStatementNestedObjects/1x5-16             15.5kB ± 0%    15.5kB ± 0%     ~     (p=0.167 n=5+5)
ParseStatementNestedObjects/1x10-16            25.2kB ± 0%    25.2kB ± 0%     ~     (all equal)
ParseStatementNestedObjects/5x5-16             6.89MB ± 0%    6.89MB ± 0%   -0.00%  (p=0.024 n=5+5)
ParseStatementNestedObjectsOrSets/1-16         8.10kB ± 0%    8.10kB ± 0%     ~     (all equal)
ParseStatementNestedObjectsOrSets/5-16         18.7kB ± 0%    18.7kB ± 0%     ~     (p=0.333 n=4+5)
ParseStatementNestedObjectsOrSets/10-16        32.2kB ± 0%    32.2kB ± 0%     ~     (p=1.000 n=5+5)
ParseStatementNestedObjectsOrSets/15-16        46.2kB ± 0%    46.2kB ± 0%     ~     (p=0.429 n=5+5)
ParseStatementNestedObjectsOrSets/20-16        60.6kB ± 0%    60.6kB ± 0%     ~     (p=0.968 n=5+4)
ParseBasicABACModule-16                        52.0kB ± 0%    52.0kB ± 0%     ~     (p=0.333 n=4+5)
ObjectLookup/5-16                               0.00B          0.00B          ~     (all equal)
ObjectLookup/50-16                              0.00B          0.00B          ~     (all equal)
ObjectLookup/500-16                             0.00B          0.00B          ~     (all equal)
ObjectLookup/5000-16                            0.00B          0.00B          ~     (all equal)
SetIntersection/5-16                             288B ± 0%      288B ± 0%     ~     (all equal)
SetIntersection/50-16                          1.85kB ± 0%    1.85kB ± 0%     ~     (all equal)
SetIntersection/500-16                         24.7kB ± 0%    24.7kB ± 0%     ~     (all equal)
SetIntersection/5000-16                         205kB ± 0%     205kB ± 0%     ~     (p=1.000 n=5+5)
SetIntersectionDifferentSize/4-16                272B ± 0%      272B ± 0%     ~     (all equal)
SetIntersectionDifferentSize/50-16               288B ± 0%      288B ± 0%     ~     (all equal)
SetIntersectionDifferentSize/500-16              288B ± 0%      288B ± 0%     ~     (all equal)
SetIntersectionDifferentSize/5000-16             288B ± 0%      288B ± 0%     ~     (all equal)
SetMembership/5-16                              0.00B          0.00B          ~     (all equal)
SetMembership/50-16                             0.00B          0.00B          ~     (all equal)
SetMembership/500-16                            0.00B          0.00B          ~     (all equal)
SetMembership/5000-16                           0.00B          0.00B          ~     (all equal)
TermHashing/10-16                               0.00B          0.00B          ~     (all equal)
TermHashing/100-16                              0.00B          0.00B          ~     (all equal)
TermHashing/1000-16                             0.00B          0.00B          ~     (all equal)
ObjectString/5/String()-16                       208B ± 0%      208B ± 0%     ~     (all equal)
ObjectString/5/json.Marshal-16                   736B ± 0%      736B ± 0%     ~     (all equal)
ObjectString/50/String()-16                    1.82kB ± 0%    1.82kB ± 0%     ~     (all equal)
ObjectString/50/json.Marshal-16                5.05kB ± 0%    5.05kB ± 0%     ~     (all equal)
ObjectString/500/String()-16                   37.6kB ± 0%    37.6kB ± 0%     ~     (all equal)
ObjectString/500/json.Marshal-16               49.9kB ± 0%    49.9kB ± 0%     ~     (p=1.000 n=4+5)
ObjectString/5000/String()-16                   368kB ± 0%     368kB ± 0%     ~     (p=0.079 n=4+5)
ObjectString/5000/json.Marshal-16               514kB ± 0%     514kB ± 0%   -0.03%  (p=0.016 n=4+5)
ObjectConstruction/shuffled_keys/5-16            880B ± 0%      880B ± 0%     ~     (all equal)
ObjectConstruction/shuffled_keys/50-16         8.80kB ± 0%    8.81kB ± 0%     ~     (p=0.238 n=4+5)
ObjectConstruction/shuffled_keys/500-16         106kB ± 0%     106kB ± 0%     ~     (p=0.421 n=5+5)
ObjectConstruction/shuffled_keys/5000-16       1.06MB ± 0%    1.06MB ± 0%     ~     (p=0.937 n=5+5)
ObjectConstruction/shuffled_keys/50000-16      10.8MB ± 0%    10.8MB ± 0%     ~     (p=0.421 n=5+5)
ObjectConstruction/increasing_keys/5-16          880B ± 0%      880B ± 0%     ~     (all equal)
ObjectConstruction/increasing_keys/50-16       8.80kB ± 0%    8.81kB ± 0%     ~     (p=0.167 n=5+5)
ObjectConstruction/increasing_keys/500-16       106kB ± 0%     106kB ± 0%     ~     (p=0.651 n=5+5)
ObjectConstruction/increasing_keys/5000-16     1.06MB ± 0%    1.06MB ± 0%     ~     (p=1.000 n=5+5)
ObjectConstruction/increasing_keys/50000-16    10.8MB ± 0%    10.8MB ± 0%     ~     (p=1.000 n=5+5)
ArrayString/5/String()-16                        144B ± 0%      144B ± 0%     ~     (all equal)
ArrayString/5/json.Marshal-16                   48.0B ± 0%     48.0B ± 0%     ~     (all equal)
ArrayString/50/String()-16                     1.82kB ± 0%    1.82kB ± 0%     ~     (all equal)
ArrayString/50/json.Marshal-16                   280B ± 0%      280B ± 0%     ~     (all equal)
ArrayString/500/String()-16                    25.8kB ± 0%    25.8kB ± 0%     ~     (all equal)
ArrayString/500/json.Marshal-16                3.10kB ± 0%    3.10kB ± 0%     ~     (all equal)
ArrayString/5000/String()-16                    241kB ± 0%     241kB ± 0%     ~     (p=0.167 n=5+5)
ArrayString/5000/json.Marshal-16               41.6kB ± 0%    41.6kB ± 0%     ~     (p=0.690 n=5+5)
SetString/5/String()-16                         24.0B ± 0%     24.0B ± 0%     ~     (all equal)
SetString/50/String()-16                         504B ± 0%      504B ± 0%     ~     (all equal)
SetString/500/String()-16                      10.5kB ± 0%    10.5kB ± 0%     ~     (all equal)
SetString/5000/String()-16                      154kB ± 0%     154kB ± 0%     ~     (all equal)

name                                         old allocs/op  new allocs/op  delta
RewriteDynamics/1-16                             1.00 ± 0%      1.00 ± 0%     ~     (all equal)
RewriteDynamics/10-16                            10.0 ± 0%      10.0 ± 0%     ~     (all equal)
RewriteDynamics/100-16                            100 ± 0%       100 ± 0%     ~     (all equal)
RewriteDynamics/1000-16                         1.00k ± 0%     1.00k ± 0%     ~     (all equal)
RewriteDynamics/10000-16                        10.0k ± 0%     10.0k ± 0%     ~     (all equal)
RewriteDynamics/100000-16                        100k ± 0%      100k ± 0%     ~     (all equal)
ParseModuleRulesBase/1-16                         115 ± 0%       115 ± 0%     ~     (all equal)
ParseModuleRulesBase/10-16                        797 ± 0%       797 ± 0%     ~     (all equal)
ParseModuleRulesBase/100-16                     7.65k ± 0%     7.65k ± 0%     ~     (all equal)
ParseModuleRulesBase/1000-16                    76.1k ± 0%     76.1k ± 0%     ~     (all equal)
ParseStatementBasicCall-16                       73.0 ± 0%      73.0 ± 0%     ~     (all equal)
ParseStatementMixedJSON-16                      1.83k ± 0%     1.83k ± 0%   +0.11%  (p=0.008 n=5+5)
ParseStatementSimpleArray/1-16                   62.0 ± 0%      63.0 ± 0%   +1.61%  (p=0.008 n=5+5)
ParseStatementSimpleArray/10-16                   219 ± 0%       220 ± 0%   +0.46%  (p=0.008 n=5+5)
ParseStatementSimpleArray/100-16                1.75k ± 0%     1.75k ± 0%   +0.06%  (p=0.008 n=5+5)
ParseStatementSimpleArray/1000-16               17.1k ± 0%     17.1k ± 0%   +0.01%  (p=0.008 n=5+5)
ParseStatementNestedObjects/1x1-16               78.0 ± 0%      78.0 ± 0%     ~     (all equal)
ParseStatementNestedObjects/5x1-16                222 ± 0%       222 ± 0%     ~     (all equal)
ParseStatementNestedObjects/10x1-16               398 ± 0%       398 ± 0%     ~     (all equal)
ParseStatementNestedObjects/1x5-16                178 ± 0%       178 ± 0%     ~     (all equal)
ParseStatementNestedObjects/1x10-16               303 ± 0%       303 ± 0%     ~     (all equal)
ParseStatementNestedObjects/5x5-16               132k ± 0%      132k ± 0%     ~     (p=0.444 n=5+5)
ParseStatementNestedObjectsOrSets/1-16           92.0 ± 0%      92.0 ± 0%     ~     (all equal)
ParseStatementNestedObjectsOrSets/5-16            278 ± 0%       278 ± 0%     ~     (all equal)
ParseStatementNestedObjectsOrSets/10-16           509 ± 0%       509 ± 0%     ~     (all equal)
ParseStatementNestedObjectsOrSets/15-16           739 ± 0%       739 ± 0%     ~     (all equal)
ParseStatementNestedObjectsOrSets/20-16           970 ± 0%       970 ± 0%     ~     (all equal)
ParseBasicABACModule-16                         1.08k ± 0%     1.08k ± 0%     ~     (all equal)
ObjectLookup/5-16                                0.00           0.00          ~     (all equal)
ObjectLookup/50-16                               0.00           0.00          ~     (all equal)
ObjectLookup/500-16                              0.00           0.00          ~     (all equal)
ObjectLookup/5000-16                             0.00           0.00          ~     (all equal)
SetIntersection/5-16                             4.00 ± 0%      4.00 ± 0%     ~     (all equal)
SetIntersection/50-16                            5.00 ± 0%      5.00 ± 0%     ~     (all equal)
SetIntersection/500-16                           5.00 ± 0%      5.00 ± 0%     ~     (all equal)
SetIntersection/5000-16                          5.00 ± 0%      5.00 ± 0%     ~     (all equal)
SetIntersectionDifferentSize/4-16                4.00 ± 0%      4.00 ± 0%     ~     (all equal)
SetIntersectionDifferentSize/50-16               4.00 ± 0%      4.00 ± 0%     ~     (all equal)
SetIntersectionDifferentSize/500-16              4.00 ± 0%      4.00 ± 0%     ~     (all equal)
SetIntersectionDifferentSize/5000-16             4.00 ± 0%      4.00 ± 0%     ~     (all equal)
SetMembership/5-16                               0.00           0.00          ~     (all equal)
SetMembership/50-16                              0.00           0.00          ~     (all equal)
SetMembership/500-16                             0.00           0.00          ~     (all equal)
SetMembership/5000-16                            0.00           0.00          ~     (all equal)
TermHashing/10-16                                0.00           0.00          ~     (all equal)
TermHashing/100-16                               0.00           0.00          ~     (all equal)
TermHashing/1000-16                              0.00           0.00          ~     (all equal)
ObjectString/5/String()-16                       19.0 ± 0%      19.0 ± 0%     ~     (all equal)
ObjectString/5/json.Marshal-16                   17.0 ± 0%      17.0 ± 0%     ~     (all equal)
ObjectString/50/String()-16                       157 ± 0%       157 ± 0%     ~     (all equal)
ObjectString/50/json.Marshal-16                   107 ± 0%       107 ± 0%     ~     (all equal)
ObjectString/500/String()-16                    1.51k ± 0%     1.51k ± 0%     ~     (all equal)
ObjectString/500/json.Marshal-16                1.01k ± 0%     1.01k ± 0%     ~     (all equal)
ObjectString/5000/String()-16                   11.0k ± 0%     11.0k ± 0%     ~     (all equal)
ObjectString/5000/json.Marshal-16               10.0k ± 0%     10.0k ± 0%     ~     (all equal)
ObjectConstruction/shuffled_keys/5-16            32.0 ± 0%      32.0 ± 0%     ~     (all equal)
ObjectConstruction/shuffled_keys/50-16            265 ± 0%       265 ± 0%     ~     (all equal)
ObjectConstruction/shuffled_keys/500-16         3.33k ± 0%     3.33k ± 0%     ~     (all equal)
ObjectConstruction/shuffled_keys/5000-16        34.9k ± 0%     34.9k ± 0%     ~     (p=0.556 n=5+4)
ObjectConstruction/shuffled_keys/50000-16        352k ± 0%      352k ± 0%     ~     (p=0.460 n=5+5)
ObjectConstruction/increasing_keys/5-16          32.0 ± 0%      32.0 ± 0%     ~     (all equal)
ObjectConstruction/increasing_keys/50-16          265 ± 0%       265 ± 0%     ~     (all equal)
ObjectConstruction/increasing_keys/500-16       3.33k ± 0%     3.33k ± 0%     ~     (all equal)
ObjectConstruction/increasing_keys/5000-16      34.9k ± 0%     34.9k ± 0%     ~     (all equal)
ObjectConstruction/increasing_keys/50000-16      352k ± 0%      352k ± 0%     ~     (p=1.000 n=5+5)
ArrayString/5/String()-16                        18.0 ± 0%      18.0 ± 0%     ~     (all equal)
ArrayString/5/json.Marshal-16                    2.00 ± 0%      2.00 ± 0%     ~     (all equal)
ArrayString/50/String()-16                        157 ± 0%       157 ± 0%     ~     (all equal)
ArrayString/50/json.Marshal-16                   2.00 ± 0%      2.00 ± 0%     ~     (all equal)
ArrayString/500/String()-16                     1.51k ± 0%     1.51k ± 0%     ~     (all equal)
ArrayString/500/json.Marshal-16                  2.00 ± 0%      2.00 ± 0%     ~     (all equal)
ArrayString/5000/String()-16                    11.0k ± 0%     11.0k ± 0%     ~     (all equal)
ArrayString/5000/json.Marshal-16                 2.00 ± 0%      2.00 ± 0%     ~     (all equal)
SetString/5/String()-16                          2.00 ± 0%      2.00 ± 0%     ~     (all equal)
SetString/50/String()-16                         6.00 ± 0%      6.00 ± 0%     ~     (all equal)
SetString/500/String()-16                        12.0 ± 0%      12.0 ± 0%     ~     (all equal)
SetString/5000/String()-16                       21.0 ± 0%      21.0 ± 0%     ~     (all equal)

I'm a little surprised about the many negative changes (= stuff getting better), but at least it makes the +20% acceptable; and RewriteDynamics() really is benchmarking something very specific that wouldn't need the array hash, but now calculates it upfront.

@srenatus srenatus merged commit 1dfa6bd into open-policy-agent:main Feb 21, 2022
@srenatus srenatus deleted the sr/ast/hash-on-insert branch February 21, 2022 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race on first usage of Eval on PrepareForEval
3 participants