stringz icon indicating copy to clipboard operation
stringz copied to clipboard

question about performance

Open missinglink opened this issue 4 years ago • 2 comments

hi, is it strictly required to call charRegex() within every invocation? wouldn't it make sense to call charRegex() once and save it in the module scope?

missinglink avatar Nov 02 '21 07:11 missinglink

@missinglink the functions are not chain-able or part of a class.. so there's no scope. it's important for FP purposes that each function is completely isolated of others

sallar avatar Nov 02 '21 09:11 sallar

I see what you mean, from a FP point of view its not ideal to have a function depend on state external to the scope of the function itself.

However I'm not sure what you mean by 'there's no scope', there is always a scope and in this case it would be a 'module scope' rather than a 'function scope' or 'global scope'?

My understanding is that bundlers will all recognise this dependency and handle it appropriately.

It seems to me that the performance advantage of not instantiating this very large regexp on every invocation outweights the dependency.

missinglink avatar Nov 02 '21 13:11 missinglink