
Issue #19693 has been updated by janosch-x (Janosch Müller). @Eregon Just in case you are interested, I tried implementing your suggestion:
Defining a `new` singleton method on the Data subclass, in Ruby and with explicit keyword arguments should be able to then use the literal kwargs optimization
Unfortunately it doesn't seem to be possible in a way that is performant and spec-compliant. Struct and Data support both list and keyword arguments in `new` now, so an override in Ruby needs to accept both types of arguments, pick one type, and check it for completeness. I [tried to get around checking by using the anonymous kwrest splat](https://gist.github.com/jaynetics/386dda6a576edd942291866c78a0db5f) (`**`) and passing that on to another generated method with explicit kwargs, but `**` brings the performance back to the original level. I guess it also (pointlessly?) creates a Hash. ---------------------------------------- Misc #19693: Data initialization is significantly slower than Struct https://bugs.ruby-lang.org/issues/19693#change-103351 * 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/