Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Micro optimization: build Hash w/
{}
For cases where all keys are present, create the Hash with all its keys with `{...}` instead of building it incrementally with multiple `Hash[]` calls. It really is a micro-optimization, but `execute_field` is on the hot path. Bench: ```ruby require "benchmark/ips" Benchmark.ips do |x| x.report("[]=") do hash = {} hash["a"] = 1 hash["b"] = 2 hash["c"] = 3 end x.report("{}") do { "a" => 1, "b" => 2, "c" => 3 } end x.compare ``` Result: ``` Warming up -------------------------------------- []= 577.660k i/100ms {} 1.438M i/100ms Calculating ------------------------------------- []= 5.809M (± 2.9%) i/s - 29.461M in 5.076542s {} 15.373M (± 0.3%) i/s - 77.651M in 5.051278s Comparison: {}=: 15372655.4 i/s []: 5808733.8 i/s - 2.65x slower ```
- Loading branch information