george43g / better-firebase-functions

This repo provides functionality for a better way of organising files, imports and function triggers in Firebase Cloud Functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Functions call singleton every invocation

alexpchin opened this issue · comments

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?

commented

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.

commented

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