Aleksandro
1/4/2016 4:32:00 PM
On 04/01/16 13:08, Stefan Ram wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> It possibly would be even better to define
>> »animate« to be a closure around »j«. Then
>> »j« would be totally private to »animate«.
>> (I don't know whether this will also make
>> accesses to »j« faster.)
>
> In the meantime, by pure coincidence, I read in a book that
> today property accesses usually are faster than accesses to
> enclosed variables. The same author also wrote that names of
> »private« properties sometimes begin with an underscore.
>
Not totally related but I wanted to mention...
I think that if the interpreter can predict what property will be
accessed permanently, so that the enclosed symbol's value will remain
unchanged for example, these accesses will be as fast.
For example:
var name = "length"
var length = someArray[name]
if the interpreter predicts that name will never change in the runtime,
the following access will be as fast as simply saying someArray.length.
If between the brackets there is an expression thing can be different
though but I bet some interpreters can optimize even that.
Why I mention this: because I think that interpreters can optimize other
things the same way.