-
Notifications
You must be signed in to change notification settings - Fork 39
Description
https://github.com/MindscapeHQ/raygun4ruby/blob/master/lib/raygun.rb#L9-L12 requires the pry gem if it is available, resucing the LoadError if not. I assume this is a convenience for development so that you can use binding.pry rather than require pry; binding.pry.
A side-effect of requiring pry like this is that it will load the pry gem if it is available in the bundle which is fairly surprising behaviour. I discovered this running derailed_benchmarks. I ran the bundle exec derailed bundle:mem task. A relevant snippet from the README of derailed_benchmarks is:
By default this task will only return results from the :default and "production" groups.
Worked example
If my Gemfile has raygun4ruby loaded in all envs, pry-rails and pry-byebug loaded in development and test envs only i.e. this:
gem 'raygun4ruby'
group :development, :test do
gem 'pry-byebug'
gem 'pry-rails'
endthen running bundle exec derailed bundle:mem shows me that Raygun4ruby is requiring pry in production and taking up 12MB e.g.
$ bundle exec derailed bundle:mem
...
raygun4ruby: 12.3398 MiB
raygun: 12.3359 MiB
pry: 11.5625 MiB
pry/cli: 7.457 MiB
/Users/eoinkelly/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/pry-byebug-3.6.0/lib/pry-byebug/cli.rb: 7.3555 MiB
pry-byebug/pry_ext: 6.6836 MiB
byebug/processors/pry_processor: 6.6758 MiB
byebug/core: 6.5977 MiB
byebug/commands: 4.7461 MiB
byebug/commands/irb: 1.9492 MiB (Also required by: /Users/eoinkelly/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/byebug-10.0.2/lib/byebug/settings/autoirb.rb)
irb: 1.9258 MiB
irb/ruby-lex: 0.957 MiB
irb/ruby-token: 0.3906 MiB
byebug/commands/break: 0.3047 MiB
byebug/context: 0.5 MiB
pry-byebug/commands: 0.6055 MiB
pry/commands: 2.0586 MiB
/Users/eoinkelly/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/pry-0.12.2/lib/pry/commands/ls.rb: 0.3281 MiB
pry/commands/ls/ls_entity: 0.3008 MiB
pry/color_printer: 0.3008 MiB
...
If I edit my Gemfile to look like
gem 'raygun4ruby'
group :development, :test do
# gem 'pry-byebug'
# gem 'pry-rails'
endand re-run the benchmark then raygun4ruby is back down to a more civilized 1.7MB
$ bundle exec derailed bundle:mem
...
raygun4ruby: 1.7383 MiB
raygun: 1.7383 MiB
httparty: 1.5391 MiB
net/http: 0.457 MiB (Also required by: net/https, httparty/net_digest_auth)
csv: 0.4531 MiB
...
Mitigations
I'm guessing that if bundler is run in production as bundle install --without=development test then this might not happen because the pry gem would not be available.
Conclusion
I think this is a bit of a "trip hazard" for folk. I would guess that pry is in most Gemfiles so unless they know enough to tweak how bundler runs in production, they may unwittingly be losing some RAM to pry in each Rails process.
Unless there is some compelling reason for requiring pry that I'm not aware of I think this gem should not 😄