
Issue #19693 has been updated by janosch-x (Janosch Müller). @byroot To me it looks as if the handling of positional args in `rb_data_s_new` / `rb_data_initialize_m` could perhaps be patched so as not to create an intermediate hash and thus greatly increase performance for this case. I might be missing a gotcha and am unsure whether its worth it, though. ---------------------------------------- Misc #19693: Data initialization is significantly slower than Struct https://bugs.ruby-lang.org/issues/19693#change-103308 * Author: janosch-x (Janosch Müller) * Status: Closed * 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/