rspec / rspec-mocks

RSpec's 'test double' framework, with support for stubbing and mocking
https://rspec.info
MIT License
1.16k stars 358 forks source link

Reduce recorder memory usage #1479

Closed xjunior closed 8 months ago

xjunior commented 2 years ago

Before this change in my test suite:

allocated memory by gem
-----------------------------------
 450.63 MB  rspec-mocks-3.11.0
 250.91 MB  activesupport-5.2.8.1
 247.35 MB  activerecord-5.2.8.1

After this change in my test suite:

allocated memory by gem
-----------------------------------
 250.92 MB  activesupport-5.2.8.1
 247.36 MB  activerecord-5.2.8.1
 198.83 MB  rspec-mocks-3.11.0
xjunior commented 1 year ago

Hello, @pirj. Any chance we're shipping this soon?

JonRowe commented 1 year ago

Can you construct a benchmark for this? It looks harmles but I'm also confused why it saves memory, its essentially the same code except for using blocks rather than lambdas

xjunior commented 1 year ago

@JonRowe hello! I got to this part of the code by debugging and profiling my own test suite. The description includes a benchmark of it.

JonRowe commented 1 year ago

@xjunior if you check the benchmarks folder you'll see the sort of thing we like to add with these changes to document them for prosperity (and allow us to re-check if it changes at a later date) this helps us to avoid churn because something works "better on my machine"

xjunior commented 1 year ago

@JonRowe I added some. It doesn't show the same results I'm showing above. I believe this is because mine is running on a bigger sample, with rails, rspec-rails and others. The results I pushed show a 30% difference on memory allocation on this specific example.

pirj commented 9 months ago

@JonRowe WDYT? I'm very much in favour of merging this.

JonRowe commented 8 months ago

This has been released in 3.12.7