1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activesupport/lib/active_support/cache
Jean Boussier b0cc7d985e Refactor MemoryStore to use Hash ordering rather than key access times
This is mainly to simplify the code and use less memory, as large hash can use quite a lot:

```ruby
>> ObjectSpace.memsize_of(1000.times.map { |i| [i, i]}.to_h)
=> 28768
>> ObjectSpace.memsize_of(10_000.times.map { |i| [i, i]}.to_h)
=> 458848
```

The performance is mostly not impacted, if not slightly better:

```ruby
require 'benchmark/ips'
require 'active_support/all'
@store = ActiveSupport::Cache::MemoryStore.new
@store.write("small", "small")
Benchmark.ips do |x|
  x.report("read:miss") { @store.read("miss") }
  x.report("read:small") { @store.read("small") }
  x.report("write:small") { @store.write("small", "small") }
end
```

6.0.3.2:
```
Warming up --------------------------------------
           read:miss    42.466k i/100ms
          read:small    25.315k i/100ms
         write:small    17.826k i/100ms
Calculating -------------------------------------
           read:miss    426.923k (± 1.9%) i/s -      2.166M in   5.074890s
          read:small    248.518k (± 2.7%) i/s -      1.266M in   5.097049s
         write:small    180.388k (± 1.6%) i/s -    909.126k in   5.041238s
```

This branch:
```
Warming up --------------------------------------
           read:miss    42.040k i/100ms
          read:small    28.364k i/100ms
         write:small    19.361k i/100ms
Calculating -------------------------------------
           read:miss    417.814k (± 2.1%) i/s -      2.102M in   5.033186s
          read:small    278.950k (± 2.8%) i/s -      1.418M in   5.088135s
         write:small    193.384k (± 1.8%) i/s -    968.050k in   5.007446s
```
2020-07-01 12:32:55 +02:00
..
strategy Duplicate the cached value before writing it in the local cache 2019-10-29 17:04:45 +01:00
file_store.rb Fix an error for FileStore.cleanup when using Sprockets 2020-06-25 23:58:30 +09:00
mem_cache_store.rb Fix test_two_classes_autoloading failure 2020-05-19 02:57:46 +09:00
memory_store.rb Refactor MemoryStore to use Hash ordering rather than key access times 2020-07-01 12:32:55 +02:00
null_store.rb Introduce keyword arguments for some AS::Cache methods 2019-09-03 17:48:40 +09:00
redis_cache_store.rb Fix Active Support failure for redis 4.2.0 with Ruby 2.8.0-dev 2020-06-10 09:25:03 +09:00