Javascript function inlining

Viewed 886

I have the following function, which copies 3 elements from one array-like object to another:

function copy(a, b) { 
    a[0] = b[0];
    a[1] = b[1];
    a[2] = b[2];
    return a;
}

This function gets called tens of thousands of timed per frame.

Almost all of the calls to it come from a single place in my code.

If I inline it manually in that single location, such that the sets are done directly in the caller, my code becomes significantly faster, meaning the engine isn't inlining it.

Is there some way to make sure JS engines inline it? This is clearly a hot function. Are there any weird annotations, or vice-versa some code pattern that doesn't allow the engine to inline functions?

I have many similar functions, to work with vectors and matrices, so it would be very cumbersome and ugly to start manually inlining all over the place.

0 Answers
Related