invertase / stripe-firebase-extensions

Repository of Firebase Extensions built by Stripe.
https://firebase.google.com/products/extensions
Apache License 2.0
437 stars 168 forks source link

Allocate more memory to user-interactive Cloud Functions #418

Open willbattel opened 2 years ago

willbattel commented 2 years ago

Feature request

Is your feature request related to a problem? Please describe.

Google Cloud Functions suffer from a major issue affecting cold starts that can really hurt user-interactive operations such as creating checkout sessions. The cold start delay can often exceed 5 seconds, often times even more, and the minimum instances feature helps some but does not completely prevent cold starts.

Please see this issue, and particularly my comment for more details, here: https://github.com/stripe/stripe-firebase-extensions/issues/68#issuecomment-1211698218

Describe the solution you'd like

From our own testing as well as results posted by other Cloud Functions users, allocating more memory to Cloud Function helps to reduce the cold start time because Google assigns the execution a higher CPU clock rate (see above link). I would like for this extension to configure the user-interactive Cloud Functions (not all 6 functions qualify as user-interactive) to run with more memory, preferably 2 GB. This could potentially be made opt-in as an extension configuration parameter.

Describe alternatives you've considered

We can manually achieve this currently by assigning more memory in the Cloud Console. Ideally, we would like to have this built into the extension so that it is synchronized in version control for multi-project environments (i.e., separate Firebase/GCP projects for development, testing, production).

Additional context

Relevant links

https://github.com/stripe/stripe-firebase-extensions/issues/68#issuecomment-1211698218

https://issuetracker.google.com/issues/158014637

https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation

willbattel commented 2 years ago

Thinking about this some more, maybe the best solution from this extension's perspective is simply some additional documentation noting the cold start issue and manually increasing memory as a mitigation option.