
Issue #19693 has been updated by janosch-x (Janosch Müller). @byroot nice idea! i've [tried it](https://gist.github.com/jaynetics/0d04eb85177140e2a84fc88aeea68764). it still doubles (instead of triples) kw init speed, at the cost of halving speed when initializing with list args: ``` orig list: 7136048.0 i/s patch list: 3115468.7 i/s - 2.29x slower patch kw: 2956280.5 i/s - 2.41x slower orig kw: 1621000.3 i/s - 4.40x slower ```
I'm not sure is spec compliant, as it would allow to call Foo.new("a", a: "also_a")
i think this one test, for structs with `keyword_init: true`, will fail: https://github.com/ruby/ruby/blame/master/test/ruby/test_struct.rb#L116 however, this gives me the idea that a simple Ruby keyword initializer (`def self.new(a: nil, b: nil); orig_new(a, b) end`) could be auto-defined, and speed tripled, if and only if `keyword_init: true` is given. this should be spec compliant. structs with `keyword_init: true` already raise an arity error when given list args. then again, i assume the idea is to rather fade out the `keyword_init` option, which doesn't even exist for `Data`? ---------------------------------------- Misc #19693: Data initialization is significantly slower than Struct https://bugs.ruby-lang.org/issues/19693#change-103397 * 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/