I am implementing an A Star algorithm and performance are more important than readability in this specific case.
Since my AStar.FindPath is occasionally called multiple times in a few milliseconds and good performance is mandatory, is it more efficient to have multiple Foo.Bar.Baz in it, or do var fooBaz = Foo.Bar.Baz at the beginning and have multiple fooBaz in it?
FindPath(o, d) {
var fooBaz = Foo.Bar.Baz;
// Multiple fooBaz
// More code...
}
VS
FindPath(o, d) {
// Multiple Foo.Bar.Baz
// More code...
}
It depends on what you do with your foo.bar.baz, and the complexity of your code.
While in principle var foobaZ should be quicker, in most cases it's going to be exactly the same, as the browser is going to be smart enough to optimize your code anyway. The key thing, is that this can only happen if you don't assign to Foo.Bar.Baz (which seems the case, otherwise you wouldn't be able to replace it with a local variable).
See it for yourself, the difference is minimal (the timing error is greater than the measured difference):