0

I use a config object to store configuration information. So something like this example:

var value = myObject.Get('name');

The actual config is stored in an array - ie config['name'] = value

There are a lot of calls to the Get() function - over 25,000. How significant would the difference be if that array was accessed directly instead of via he Get() call?

Also - in an animation that 25,000 could be done 60 times per second (!)

Tomasz Nurkiewicz
  • 324,247
  • 67
  • 682
  • 662
Richard
  • 4,650
  • 3
  • 25
  • 45

2 Answers2

0

I would recommend not overoptimizing until you have means to test how much this actually effects things. Depending on the situations, this whole call could just end up inlined anyway.

loganfsmyth
  • 146,797
  • 27
  • 317
  • 241
0

The direct access should be faster, but you should do some tests, because the code performance is often influenced by the js engine.

For example, it's about 50% faster to access an object's key through the dot synthax (obj.key) than the asociative array like one (obj["key"]) in chrome, while in firefox it's the other way around.
I recommend you don't do micro-optimisations before you end your project and only after you do some testing/research.

gion_13
  • 40,487
  • 10
  • 96
  • 107