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

Gem memory at boot time #87

Open
jamescook opened this issue Dec 13, 2024 · 1 comment
Open

Gem memory at boot time #87

jamescook opened this issue Dec 13, 2024 · 1 comment

Comments

@jamescook
Copy link

Problem

The gem eagerly loads all API endpoint wrappers, which bloats the memory footprint when the gem is loaded. For our particular use-case, we only need a handful of API endpoints.

Measurements

Boot-time memory measurements as of gem version 2.34.0 using bundle exec derailed_benchmarks bundle:mem in our Rails application. Seems you need to re-run the command several times as the measurement is not very precise/consistent between invocations.

CUT_OFF=0.001 bundle exec derailed bundle:mem | grep chargebee

3.2188 MiB
4.0156 MiB
6.5313 MiB
3.5938 MiB
3.7344 MiB

Now, on the latest chargebee gem version (2.47.1), which compared to 2.34 has introduced several more API endpoint wrappers shows memory usage has increased:

9.75 MiB
8.625 MiB
9.2813 MiB
7.7031 MiB
11.2656 MiB

My refactoring of lib/chargebee.rb to use autoload (master...jamescook:chargebee-ruby:use-autoload). Here we can see memory usage drops sharply at boot time:

0.125 MiB
0.0469 MiB
0.125 MiB
0.1719 MiB

I only used autoload as a POC - zeitwerk is likely a better solution longterm but requires more code changes whereas using autoload I only had to modify lib/chargebee.rb - this is assuming the specs validated the changes thoroughly enough.

My machine specs:

  • Ruby 3.3.6
  • Apple M1 max
@cb-alish
Copy link
Collaborator

Hi @jamescook , thanks for raising this ! We'll review it and get back to you soon.

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

No branches or pull requests

2 participants