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

Stripe import is very slow #1427

Open
silviogutierrez opened this issue Nov 25, 2024 · 3 comments
Open

Stripe import is very slow #1427

silviogutierrez opened this issue Nov 25, 2024 · 3 comments

Comments

@silviogutierrez
Copy link

Describe the bug

I looked around, searched the issues and even googled. Surprised this hasn't come up.

Just importing the library adds 500ms to startup time. There's got to be a way to lazy load parts.

This is on a top of the line Mac with SSD.

To Reproduce

# Takes about 20 ms
time python -c "print('ok')";

# Takes bout 500ms
time python -c "print('ok'); import stripe"

Expected behavior

For serverless setups, startup time is pretty important.

Even for local development, django's runserver or uvicorn's reload are both much slower with imports like these.

Of course you can do the import locally everywhere stripe is used, but this can be problematic.

At the very least, some guidance in the docs on how to do imports and have a lazy-loaded client would help. Something like a central get_stripe_client() -> Stripe or the like. And cover thread-safety in here.

Code snippets

No response

OS

macOS

Language version

3.12.1

Library version

11.3.0

API version

2020-08-27

Additional context

No response

@devraj
Copy link

devraj commented Nov 25, 2024

Out of curiosity what serverless platform are you deploying to? This would only be an issue on cold starts, is that correct?

@silviogutierrez
Copy link
Author

For production, yes, it's mostly an issue with cold starts. If you use python's importtime you can see Stripe takes up a big, big chunk. See more here: https://adamj.eu/tech/2023/03/02/django-profile-and-improve-import-time/

Cold start platforms: Google Cloud Run in my case.

But it also has local dev implications. Django and FastAPI rely on an autoreloading server. Unlike frontend tools like vite, there's no concept of hot module reloading. So this library — with no usage, just importing — is responsible for a 500ms lag in restarts.

Imagine a few other libraries like this (Google storage does the same thing), and it starts to add up.

@prathmesh-stripe
Copy link
Contributor

Thanks for reporting this. We will be looking into SDK optimizations in the new year.

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