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
  • 334,321
  • 69
  • 703
  • 674
Richard
  • 4,809
  • 3
  • 27
  • 46

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
  • 156,129
  • 30
  • 331
  • 251
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
  • 41,171
  • 10
  • 96
  • 108