You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Detach Messages::Rotator from SecureCompareRotator
Prior to this commit, `ActiveSupport::SecureCompareRotator` used
`ActiveSupport::Messages::Rotator` for part of its rotation logic, even
though `SecureCompareRotator` is entirely unrelated to messages. This
made it precarious to alter `Messages::Rotator`, especially because
`Messages::Rotator` was `prepend`ed to `SecureCompareRotator` rather
than `include`d.
This commit reimplements `SecureCompareRotator` without
`Messages::Rotator`, which simplifies the logic and, as a bonus,
improves performance:
```ruby
# frozen_string_literal: true
require "benchmark/ips"
require "active_support/all"
comparer = ActiveSupport::SecureCompareRotator.new("new secret")
comparer.rotate("old secret")
Benchmark.ips do |x|
x.report("compare old") do
comparer.secure_compare!("old secret")
end
end
```
__Before__
```
Warming up --------------------------------------
compare old 72.073k i/100ms
Calculating -------------------------------------
compare old 719.844k (± 1.0%) i/s - 3.604M in 5.006682s
```
__After__
```
Warming up --------------------------------------
compare old 147.486k i/100ms
Calculating -------------------------------------
compare old 1.473M (± 0.9%) i/s - 7.374M in 5.006655s
```
0 commit comments