Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a frozen copy of Rails.root in AppNotifications and LogInterceptor #86

Merged
merged 1 commit into from
Dec 6, 2014
Merged

Conversation

modosc
Copy link
Collaborator

@modosc modosc commented Dec 6, 2014

i was playing with https://github.com/schneems/derailed_benchmarks while debugging a memory leak in an application and i saw that meta_request was allocating a lot of memory:

$ bundle exec rake -f perf.rake perf:mem RAILS_ENV=development
Booting: development
Running 1 times
Total allocated 155114
Total retained 1160

allocated memory by gem
-----------------------------------
meta_request-0.3.4 x 17136862
activesupport-4.1.8 x 700213
haml-4.0.6 x 346715
actionview-4.1.8 x 328915
ruby-2.1.5/lib x 327681```

the specific culprits were:

allocated memory by location
-----------------------------------
gems/meta_request-0.3.4/lib/meta_request/app_notifications.rb:11 x 13325502
gems/meta_request-0.3.4/lib/meta_request/log_interceptor.rb:39 x 3758621

both of which involve converting Rails.root from a Pathname into a String.

this change adds a MetaRequest.rails_root method which caches a frozen copy of Rails.root.to_s and drops the total memory allocation of a rails boot to 40% of the previous value:

Booting: development
Running 1 times
Total allocated 67646
Total retained 1217

allocated memory by gem
-----------------------------------
meta_request/lib x 6846874
activesupport-4.1.8 x 700143
haml-4.0.6 x 346420
actionview-4.1.8 x 328915
ruby-2.1.5/lib x 327681

allocated memory by location
-----------------------------------
git/rails_panel/meta_request/lib/meta_request/log_interceptor.rb:39 x 3663501
git/rails_panel/meta_request/lib/meta_request/app_notifications.rb:11 x 3130480

@dejan
Copy link
Owner

dejan commented Dec 6, 2014

This is a great finding, thanks!

dejan added a commit that referenced this pull request Dec 6, 2014
use a frozen copy of Rails.root in AppNotifications and LogInterceptor
@dejan dejan merged commit 439c3cf into dejan:master Dec 6, 2014
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