Skip to content

Commit

Permalink
Update array hash keys to integers
Browse files Browse the repository at this point in the history
Running benchmark.rb prior to change:
```
Warming up --------------------------------------
        test_no_args   526.602k i/100ms
Calculating -------------------------------------
        test_no_args      5.172M (± 1.8%) i/s -     26.330M in   5.092880s
Calculating -------------------------------------
        test_no_args     4.000k memsize (     0.000  retained)
                       100.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)
Warming up --------------------------------------
      test_with_args   221.217k i/100ms
Calculating -------------------------------------
      test_with_args      2.203M (± 5.6%) i/s -     11.061M in   5.045789s
Calculating -------------------------------------
      test_with_args    12.000k memsize (     0.000  retained)
                       300.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)
```

After:
```
Warming up --------------------------------------
        test_no_args   529.096k i/100ms
Calculating -------------------------------------
        test_no_args      5.247M (± 1.3%) i/s -     26.455M in   5.042306s
Calculating -------------------------------------
        test_no_args     4.000k memsize (     0.000  retained)
                       100.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)
Warming up --------------------------------------
      test_with_args   331.604k i/100ms
Calculating -------------------------------------
      test_with_args      3.471M (± 0.8%) i/s -     17.575M in   5.064376s
Calculating -------------------------------------
      test_with_args    12.000k memsize (     0.000  retained)
                       300.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)
```
  • Loading branch information
CKolkey authored Sep 12, 2024
1 parent 91e441b commit 17b82cd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/memery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def define_memoized_method!(klass, method_name, condition: nil, ttl: nil)
end

cache_store = (@_memery_memoized_values ||= {})
cache_key = original_arity.zero? ? method_key : [method_key, *args]
cache_key = original_arity.zero? ? method_key : [method_key, *args].hash
cache = cache_store[cache_key]

return cache.result if cache&.fresh?(ttl)
Expand Down

0 comments on commit 17b82cd

Please sign in to comment.