Givi made this answer irrelevant. Please see the comments for clarification.
It appears that searching for a user-defined function within a user-defined object is slower compared to searching for a function bound to a local variable, which aligns with your initial assumption.
Interestingly, accessing Math.*
functions seems to be quicker, possibly due to internal optimizations within the V8 engine. This means that storing built-in functions in a local variable (i.e., "caching") may actually result in slower performance, while caching user-defined functions can lead to faster execution.
For further insights and proof of concept, you can refer to this JavaScript performance test, showcasing the speed discrepancies between Math.*
functions and their equivalent var x = Math.x
versions.
In addition, I came across a line in your question suggesting optimization of built-in functions in Chrome's V8 Engine:
I'd speculate that this is due to some optimizations on built-in
functions in Chrome's V8 Engine.
While I cannot confirm it with absolute certainty, there does seem to be evidence supporting this theory.