From: "byroot (Jean Boussier) via ruby-core" Date: 2023-05-25T21:10:54+00:00 Subject: [ruby-core:113664] [Ruby master Misc#19693] Data initialization is significantly slower than Struct Issue #19693 has been updated by byroot (Jean Boussier). @janosch-x based on the discussion in #19278, I don't think it's possible as `Data` specifically designed so that `initialize` always receive keyword arguments. So given the spec (which we can't change) I don't see how it could be made performant, but maybe someone has an idea? ---------------------------------------- Misc #19693: Data initialization is significantly slower than Struct https://bugs.ruby-lang.org/issues/19693#change-103309 * 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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/