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

Requiring gem takes over one second on a modest VPS #1432

Open
mperham opened this issue Jul 11, 2024 · 1 comment
Open

Requiring gem takes over one second on a modest VPS #1432

mperham opened this issue Jul 11, 2024 · 1 comment

Comments

@mperham
Copy link

mperham commented Jul 11, 2024

Describe the bug

I'm using a basic DigitalOcean droplet and the Stripe gem takes over one second to require with Ubuntu 24.04/Ruby 3.2.

mike@svr-20240711:/opt/billing$ time ruby -e "require 'stripe'"

real	0m1.364s
user	0m0.637s
sys	0m0.106s
mike@svr-20240711:/opt/billing$ time ruby -e "require 'stripe'"

real	0m1.391s
user	0m0.584s
sys	0m0.087s
mike@svr-20240711:/opt/billing$ time ruby -e "require 'stripe'"

real	0m1.125s
user	0m0.535s
sys	0m0.076s
mike@svr-20240711:/opt/billing$ time ruby -e "require 'stripe'"

real	0m1.271s
user	0m0.529s
sys	0m0.097s

Even on my fast M1 laptop, requiring takes 250-300ms:

apache2/sites-enabled (podman *) % time ruby -e "require 'stripe'"
ruby -e "require 'stripe'"  0.11s user 0.04s system 44% cpu 0.333 total
apache2/sites-enabled (podman *) % time ruby -e "require 'stripe'"
ruby -e "require 'stripe'"  0.11s user 0.04s system 52% cpu 0.274 total
apache2/sites-enabled (podman *) % time ruby -e "require 'stripe'"
ruby -e "require 'stripe'"  0.10s user 0.03s system 60% cpu 0.223 total

lib/stripe.rb requires dozens of files, most of which are not used. Instead of eager loading everything, would you consider moving to autoload constants? My usecase is single-threaded CGI so I'm requiring the gem for each request and this slowness adds a second of latency for every pageload.

As another data point, I maintain Sidekiq and it takes half the time to require (100-150ms).

To Reproduce

See above.

Expected behavior

I'd like to see the gem load in under 100ms.

Code snippets

No response

OS

Ubuntu 24.04

Language version

Ruby 3.2.3

Library version

stripe-ruby v12.1.0

API version

not sure

Additional context

No response

@mperham mperham added the bug label Jul 11, 2024
@xavdid-stripe
Copy link
Member

Thanks for filing! That's definitely not the experience we want; we'll take a closer look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants