Skip to content

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

@mperham

Description

@mperham

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions