Skip to content

Potential small performance optimizations #27

@dead-claudia

Description

@dead-claudia

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.

  1. In this function, it's much faster to use const out = arr.slice(), since engines provide optimized code gen for it.

  2. 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.)

  3. Consider using k != null ? k.key : undefined, etc. instead of k && k.key. Engines struggle to optimize the latter, especially when it's not like if (x) ....

  4. 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.

  5. 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.

  6. 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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions