
Issue #19693 has been updated by nobu (Nobuyoshi Nakada). `Data.new` creates a Hash and initializes via the Hash. The following line results in similar performance: ```ruby x.report('keywords') { S.new(a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10) } ``` ``` Warming up -------------------------------------- Struct 273.727k i/100ms keywords 75.597k i/100ms Data 75.350k i/100ms Calculating ------------------------------------- Struct 5.234M (± 0.7%) i/s - 26.278M in 5.020698s keywords 867.555k (± 4.9%) i/s - 4.385M in 5.067422s Data 862.600k (± 5.1%) i/s - 4.370M in 5.082609s Comparison: Struct: 5234123.3 i/s keywords: 867554.8 i/s - 6.03x slower Data: 862599.6 i/s - 6.07x slower ``` ---------------------------------------- Misc #19693: Data initialization is significantly slower than Struct https://bugs.ruby-lang.org/issues/19693#change-103302 * Author: janosch-x (Janosch Müller) * Status: Open * Priority: Normal ---------------------------------------- Maybe there is potential to make it as fast as Struct? ```ruby require 'benchmark/ips' S = Struct.new(:a, :b, :c, :d, :e, :f, :g, :h, :i, :j) D = Data.define(:a, :b, :c, :d, :e, :f, :g, :h, :i, :j) Benchmark.ips do |x| x.report('Struct') { S.new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) } x.report('Data') { D.new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) } x.compare! end; 1 # => [...] # => Struct: 6916530.4 i/s # => Data: 1507259.5 i/s - 4.59x slower ``` -- https://bugs.ruby-lang.org/