george43g / better-firebase-functions

This repo provides functionality for a better way of organising files, imports and function triggers in Firebase Cloud Functions
Mozilla Public License 2.0
179 stars 15 forks source link

Functions call singleton every invocation #50

Open alexpchin opened 1 year ago

alexpchin commented 1 year ago

As this package uses eval('require') does that mean that a singleton created every time the function gets executed? We're having a problem with a setup function being called lots of times in the app and we're wondering if this library may cause the problem by the way it requires files?

george43g commented 1 year ago

eval('require') is used instead of just 'require' because when the code is packed, webpack (vercel/ncc) will include all of the required source code in every single transpiled function, increasing cold start time.

I have not yet had a chance to investigate Firebase Function's compatibility with the new esm 'import' statements, which might defeat the purpose of the entire optimisation. I need time to investigate further on this.

george43g commented 1 year ago

When you say setup function, do you mean initializeApp() that's used to create Firestore etc... instances?