flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Justin Mclean <jus...@classsoftware.com>
Subject Re: Private properties are undefined in JS and null in AS
Date Sun, 04 Jun 2017 01:40:38 GMT
Hi,

So here’s some data for you:

In string_old.js:

var s;

for (var i = 0; i < 1e8; i++) {
    if (s == "") {
    }
}

In string.js:

var s = "";

for (var i = 0; i < 1e8; i++) {
    if (s === "") {
    }
}

time node string.js
real	0m0.246s
user	0m0.114s
sys	0m0.046s

time node string_old.js
real	0m2.496s
user	0m2.452s
sys	0m0.019s

The === and setting to “" is an order of magnitude faster (in node anyway), similar results
with initialising to null rather than “”.

Running similar code (converted to AS ) through the chrome profiler gives results where setting
to null and using === is faster.

It even twice as fast if you initialise the variable and compare on every time through the
loop. So 1e8 lots = null and a === is faster than no initialisation and a ==.

I think what is happening currently is that because we are not initialising the variable it’s
doing a implicit cast on every every comparison that is very expensive when using != and ==,
using === and !== significantly speeds this up but then you have the issues of uninitialise
strings and objects being null in AS and undefined in JS but it still twice as fast.

BTW I do note that we are setting ints to 0. I assume because of similar reasons? But it seems
you were not concerned with the overhead of this?

Thanks,
Justin
Mime
View raw message