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

Not sure on slow times #22

Closed lumenlunae closed 2 years ago

lumenlunae commented 3 years ago

Hi! I really appreciate the work you did here. I took part of the weekend to implement this in my app that had 50 functions. Wasn't terrible, and I was really excited to see the kind of improvements in execution time.

😅 Well, I think cold boot times went up across the board.

This is my index.ts `import { exportFunctions } from 'better-firebase-functions';

import camelCase from 'camelcase'; import { sep } from 'path';

function funcNameFromRelPath(relPath) { let isFunction = false; if (relPath.indexOf('https/') === 0) { isFunction = true; }

const relPathArray = relPath.split(sep); / ? / const fileName = relPathArray.pop(); / ? / const relDirPathFunctionNameChunk = relPathArray.map((pathFragment) => camelCase(pathFragment)).join('-'); const fileNameFunctionNameChunk = isFunction ? fileName.split('.')[0] : camelCase(fileName.split('.')[0]); const funcName = relDirPathFunctionNameChunk ? ${relDirPathFunctionNameChunk}-${fileNameFunctionNameChunk} : fileNameFunctionNameChunk; const final = isFunction ? funcName.replace('https-', '') : funcName.replace(sep, '-'); return final; }

exportFunctions({ __filename, exports, functionDirectoryPath: './firestore', funcNameFromRelPath, searchGlob: '*/.[jt]s', enableLogger: true, }); `

I needed this to be backwards compatible with the function names used in the app, and so I could test this all on a staging server before pushing to the production app.

With logger enabled, I get this when I run my tests: [better-firebase-functions] Directory Glob Search: 6.141ms [better-firebase-functions] Load & Export Modules (Deployment): 2045.671ms

Does that seem... normal?

For example, I have a /users/ onUpdate trigger that was consistently 1.5+ seconds. I removed all code from it, deployed, and when it so my file was literally just:

` const functions = require('firebase-functions');

export default functions.firestore.document('users/{userID}').onUpdate(async (change, context) => {

}); `

and still was hitting 1.5. That can't really be the normal cost to come from cold boot for any function, is it?

All help and thoughts appreciated! Thank you!

george43g commented 2 years ago

Just saw this, please reopen this issue if you still need help with it.