Hi all,
In some
<https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/preloader/association.rb#L126>
places
<https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/preloader/association.rb#L154>
new
array creates as a Array(). If we replace it to a [], we increase
performance about 1.7 times:
def old_slow
Array(123)
end
def new_fast
[123]
end
Benchmark.ips do |x|
x.report("new_fast") { new_fast }
x.report("old_slow") { old_slow }
x.compare!
end
Calculating -------------------------------------
new_fast 184.920k i/100ms
old_slow 150.931k i/100ms
-------------------------------------------------
new_fast 7.528M (± 4.4%) i/s - 37.724M
old_slow 4.408M (± 4.3%) i/s - 22.036M
Comparison:
new_fast: 7528299.2 i/s
old_slow: 4408283.1 i/s - 1.71x slower
What do you think about it?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.