Hacker News new | ask | show | jobs
by seanwilson 1732 days ago
> My rule of thumb these days in JS/TS is all functions with more than 2 parameters should be refactored to a single object parameter using destructuring.

Does this create garbage for the garbage collector (which might be an issue for inner loops)?

1 comments

In theory yes. But for hot inner loops you will probably get it optimized away. (This is a common pattern so optimizer try to find it and undo it. Furthermore hidden classes for objects are common and when you destructure directly in the argument list escape analysis is pretty easy) It probably does hurt your performance for warm and cold code but that likely isn't too significant.

So yes, if performance is critical you should probably profile and consider avoiding this pattern, but for most cases the performance impact is very minor.