Skip to content

Conversation

@moberegger
Copy link

@moberegger moberegger commented Jun 18, 2025

Follow up to #14. This adopts some of the block param changes from #15.

Benchmarks below to just test the array! DSL both with and without a block in a manner that avoids diluting the change is much as possible.


json.array!
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
              before   695.095k i/100ms
               after   916.521k i/100ms
Calculating -------------------------------------
              before      8.361M (± 2.2%) i/s  (119.61 ns/i) -     42.401M in   5.074102s
               after     12.024M (± 1.5%) i/s   (83.16 ns/i) -     60.490M in   5.031704s

Comparison:
               after: 12024496.6 i/s
              before:  8360774.5 i/s - 1.44x  slower

Calculating -------------------------------------
              before    40.000  memsize (     0.000  retained)
                         1.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)
               after    40.000  memsize (     0.000  retained)
                         1.000  objects (     0.000  retained)
                         0.000  strings (     0.000  retained)

Comparison:
              before:         40 allocated
               after:         40 allocated - same

# Where array = [1, 2, 3]
json.array! array do |item|
end
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
              before   307.043k i/100ms
               after   345.351k i/100ms
Calculating -------------------------------------
              before      3.309M (± 1.6%) i/s  (302.20 ns/i) -     16.580M in   5.011739s
               after      3.761M (± 3.6%) i/s  (265.90 ns/i) -     18.994M in   5.058330s

Comparison:
               after:  3760855.9 i/s
              before:  3309112.8 i/s - 1.14x  slower
Calculating -------------------------------------
              before   160.000  memsize (    40.000  retained)
                         4.000  objects (     1.000  retained)
                         0.000  strings (     0.000  retained)
               after   160.000  memsize (    40.000  retained)
                         4.000  objects (     1.000  retained)
                         0.000  strings (     0.000  retained)

Comparison:
              before:        160 allocated
               after:        160 allocated - same

json.array! posts, partial: "post", as: :post
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
              before     1.303k i/100ms
               after     1.595k i/100ms
Calculating -------------------------------------
              before      4.748k (±34.2%) i/s  (210.60 μs/i) -     22.151k in   5.104390s
               after      4.729k (±42.3%) i/s  (211.47 μs/i) -     20.735k in   5.110369s

Comparison:
              before:     4748.2 i/s
               after:     4728.7 i/s - same-ish: difference falls within error
Calculating -------------------------------------
              before     5.952k memsize (   560.000  retained)
                        80.000  objects (     5.000  retained)
                        15.000  strings (     0.000  retained)
               after     5.952k memsize (   560.000  retained)
                        80.000  objects (     5.000  retained)
                        15.000  strings (     0.000  retained)

Comparison:
              before:       5952 allocated
               after:       5952 allocated - same

@moberegger moberegger marked this pull request as ready for review June 18, 2025 19:13
Comment on lines 124 to 126
if _partial_options?(options)
options[:collection] = collection
_render_partial_with_options options
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I should also add a benchmark for array! partial:...

@moberegger moberegger merged commit f3a24a2 into main Jun 18, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants