Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a specialised helper to return frozen dups
In the Datadog::Tracing::Correlation::Identifier the unfrozen copies of strings are then frozen again: that's a step that can be skipped if the original value is already frozen, so we can save allocations. require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" gem "benchmark-memory" end Benchmark.ips do |x| x.report("+(-@).freeze") { v = "foo"; c = +(-v).freeze } x.report("-v") { v = "foo"; c = -v } x.compare! end Benchmark.memory do |x| x.report("+(-@).freeze") { v = "foo"; c = +(-v).freeze } x.report("-v") { v = "foo"; c = -v } x.compare! end Warming up -------------------------------------- +(-@).freeze 691.075k i/100ms -v 886.370k i/100ms Calculating ------------------------------------- +(-@).freeze 6.965M (± 0.5%) i/s - 35.245M in 5.060545s -v 8.839M (± 0.6%) i/s - 44.318M in 5.014288s Comparison: -v: 8838792.7 i/s +(-@).freeze: 6964819.0 i/s - 1.27x slower Calculating ------------------------------------- +(-@).freeze 80.000 memsize ( 0.000 retained) 2.000 objects ( 0.000 retained) 1.000 strings ( 0.000 retained) -v 40.000 memsize ( 0.000 retained) 1.000 objects ( 0.000 retained) 1.000 strings ( 0.000 retained) Comparison: -v: 40 allocated +(-@).freeze: 80 allocated - 2.00x more
- Loading branch information