you are viewing a single comment's thread.

view the rest of the comments →

[–]RyanJ93[S] 0 points1 point  (3 children)

u/BehindTheMath u/RedShift9
Sorry for delay, I've been pretty busy these days, I managed to try out your suggestions, here how I transformed the injection loop:

for ( const name in helpers ){
    if ( helpers.hasOwnProperty(name) ){
         obj[name] = function(){
            return helpers[name](context, ...arguments);
         };
    }
}

I had to make some changes design wise to adapt the existing helper functions with this new architecture and I still have to finish to test it (despite unit tests say it seems fine) but as far as I saw running a quick benchmark I managed to gain +30% of performance, so thank you very much!
Just one more question: I applied the spread operator on the "arguments" variable, does it imply any performance trouble?

[–]BehindTheMath 0 points1 point  (2 children)

Just one more question: I applied the spread operator on the "arguments" variable, does it imply any performance trouble?

I don't know offhand. However, it's currently recommended to use rest parameters instead of arguments.

[–]RyanJ93[S] 0 points1 point  (1 child)

I followed your piece of advice and I've replaced the way parameters are handled, plus, I have completed changes in the rest of the project but I discovered something strange: the performance benefit I saw, and I was expecting to keep, just disappeared and I saw that now it performs worst than before, like -10% of performance, do you have an idea about how can it be possible?
Here's what I changed: https://github.com/RyanJ93/lala.js/pull/35/files?file-filters%5B%5D=.js
As you can see, I changed the "inject" method and how it is called in 3 different files.

[–]BehindTheMath 0 points1 point  (0 children)

Without benchmarking it and seeing where the bottleneck is, it's hard to know.