-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Edit: My benchmark memories are apparently out of date...
I haven't actually profiled this, but I thought I'd take a gander through a few things.
-
In this function, it's much faster to useconst out = arr.slice(), since engines provide optimized code gen for it. -
In this function and this function, see if starting with an empty array literal is faster. (For some reason, engines are often faster with that than with a pre-allocated array.) -
Consider using
k != null ? k.key : undefined, etc. instead ofk && k.key. Engines struggle to optimize the latter, especially when it's not likeif (x) .... -
Be careful about polymorphism. That will come back to bite you very quickly performance-wise if you're not careful, and the library has a very large amount of it, largely by necessity.
-
If it's super simple like this, this, or this, you might as well just inline it. The function call overhead, especially when dealing with higher order functions, could screw up the engine's optimizer, giving you megamorphic perf hits earlier than what you'd like.
-
Avoid closures where you can. They get deadly in a hurry, and no JS engine is quite as smart and magical as LuaJIT is when it comes to optimizing higher order functions.
Also, have you considered using class Map { ... } for hamt.Map? It might smooth out your code a little by moving the class aliasing boilerplate out of the functional API stuff.