4c4f4c385a
In #46612, a check was added to only attempt metadata extraction if the message looks like a JSON object (i.e. starts with "{"), thus avoiding an unnecessary JSON parse and possible exception. This commit extends the check to only attempt metadata extraction if the message looks like a metadata wrapper object (i.e. has the "_rails" key). This avoids an unnecessary JSON parse of JSON object messages that don't have metadata. **Benchmark** ```ruby require "benchmark/ips" require "active_support/all" verifier = ActiveSupport::MessageVerifier.new("secret", serializer: JSON) message_100 = verifier.generate({ content: "x" * 100 }) message_1m = verifier.generate({ content: "x" * 1_000_000 }) Benchmark.ips do |x| x.report("100 chars") do verifier.verify(message_100) end x.report("1m chars") do verifier.verify(message_1m) end end ``` **Before** ``` Warming up -------------------------------------- 100 chars 2.803k i/100ms 1m chars 6.000 i/100ms Calculating ------------------------------------- 100 chars 27.762k (± 1.6%) i/s - 140.150k in 5.049649s 1m chars 83.516 (±16.8%) i/s - 402.000 in 5.037269s ``` **After** ``` Warming up -------------------------------------- 100 chars 3.360k i/100ms 1m chars 9.000 i/100ms Calculating ------------------------------------- 100 chars 33.480k (± 1.7%) i/s - 168.000k in 5.019311s 1m chars 113.373 (±15.0%) i/s - 549.000 in 5.023443s ``` |
||
---|---|---|
.. | ||
bin | ||
lib | ||
test | ||
.gitignore | ||
activesupport.gemspec | ||
CHANGELOG.md | ||
MIT-LICENSE | ||
Rakefile | ||
README.rdoc |
= Active Support -- Utility classes and Ruby extensions from Rails Active Support is a collection of utility classes and standard library extensions that were found useful for the Rails framework. These additions reside in this package so they can be loaded as needed in Ruby projects outside of Rails. You can read more about the extensions in the {Active Support Core Extensions}[https://edgeguides.rubyonrails.org/active_support_core_extensions.html] guide. == Download and installation The latest version of Active Support can be installed with RubyGems: $ gem install activesupport Source code can be downloaded as part of the Rails project on GitHub: * https://github.com/rails/rails/tree/main/activesupport == License Active Support is released under the MIT license: * https://opensource.org/licenses/MIT == Support API documentation is at: * https://api.rubyonrails.org Bug reports for the Ruby on Rails project can be filed here: * https://github.com/rails/rails/issues Feature requests should be discussed on the rails-core mailing list here: * https://discuss.rubyonrails.org/c/rubyonrails-core