So, the memory used by dry-monitor was reduced from 13.4 MiB to 0.75 Mib. And the impact on the memory usage of a small dry-web-roda app was bigger than that: from 42.4297 MiB to 26.1211 MiB.
I did not analyze how derailed_benchmarks make its maths. But it’s clear that rouge has a lot of cool components that are not used by dry-monitor. Then, Why do not get rid of it?
Please, let me know what you think about this. Thank you.
Oh wow, I did not expect that. I’m all for limiting requires to what you actually need. In fact, I’m a strong believer that all gems should be designed in a way that they always provide cherry-pickable components.
@solnic also, I checked my job project for object allocation and found interesting things:
$ bundle exec derailed bundle:objects
Measuring objects created by gems in groups [:default, "production"]
Total allocated: 91115563 bytes (800628 objects)
Total retained: 15093944 bytes (134684 objects)
allocated memory by gem
-----------------------------------
10664845 rouge-2.2.1
8722637 ruby-2.4.2/lib
8059914 newrelic_rpm-4.2.0.334
6488996 mime-types-3.1
4489137 dry-initializer-2.3.0
As you can see, rouge allocate more objects raise than other dependencies. And also, this dependency needs only for color output. Sometimes it can break production (when logger services doesn’t support the color format, for example).
That’s why I have a question: WDYT if we make rouge dependency as optional? I mean if a user wants to use rouge they can install the gem and that’s all. Also, a user gets control on color/not color logs for any environments.
begin
require 'rouge'
module Dry
module Monitor
module SQL
class Logger
# use rouge lexer and other stuff
end
end
end
end
rescue LoadError
module Dry
module Monitor
module SQL
class Logger
# logger without color formatter
end
end
end
end
end
Yeah, it should be optional. I just wanted to have colors and put it there by default. Logger is configurable so it is very easy to add config setting for disabling colors.