[Laszlo-dev] New, improved class arguments processing
Max Carlson
max at openlaszlo.org
Fri Feb 22 13:23:07 PST 2008
P T Withington wrote:
> Can you either explain the things you measured, or perhaps just show the
> tests? I'd be interested to measure the case you are worrying about, say:
Sorry, I should have mentioned the tests are checked in as
test/performance/typeof-instance-of.lzx
> 3 instanceof Function
var f = function() {}
function typeOfFunction() {
for (var i = 0; i < iterations; i++) {
typeof f == 'function';
}
}
function instanceOfFunction() {
for (var i = 0; i < iterations; i++) {
f instanceof Function;
}
}
> i.e., what is the cost of a failed instanceof, vs. a successful one?
I added a test for this, and here are some numbers for dhtml Firefox on
OS X:
instanceof : 25.45us ± 8.47 [15.00..40.00]/100
instanceof that fails : 23.45us ± 5.49 [15.00..35.00]/100
And swf8:
instanceof : 29.65us ± 4.40 [15.00..35.00]/100
instanceof that fails : 24.35us ± 3.67 [15.00..30.00]/100
Still pretty expensive. I bet instanceof is waaay faster in AVM2, so it
might make sense to do some of these optimizations in the compiler for
just the JS1/AS2 backends. In the mean time, we can use this knowledge
to get the best performance possible in performance-critical sections.
> Do you have measurements that indicate the new consolidated arglist
> processing is actually slower than the old processing of args,
> constraints, and styles? I would have expected the simplifications in
> applyArgs et al. would more than make up for any additional overhead.
I bet it's faster overall now too - though I don't have any measurements
to prove it. I was just curious how much overhead instanceof has.
For example, it's clear to me we should always use 'typeof function'
instead of 'instanceof Function':
typeof function : 12.75us ± 2.50 [10.00..15.00]/100
instanceof function : 27.50us ± 2.51 [25.00..30.00]/100
> Also, it might be more profitable to work on the idea of computing a
> custom applyArgs method for each class at compile time to eliminate all
> of the remaining interpretation of the arglist.
That would be great. Every little bit helps! One bit I found
surprising is how expensive property lookups are:
property lookup : 17.95us ± 2.76 [15.00..25.00]/100
typeof is slightly cheaper:
typeof : 17.40us ± 2.97 [10.00..25.00]/100
> On 2008-02-20, at 19:23 EST, Max Carlson wrote:
>
>> Hi Tucker,
>>
>> I've been working a few kinks out of the runtime, and reading the docs
>> on LzNode.construct(), which say:
>>
>> @param Object args: A dictionary of initialization arguments that should
>> * be applied
>> * to the instance. This contains any arguments that are default
>> arguments
>> * written in the class definition. Note that initial value
>> * expressions (`$once{...}`) and constraints (`${...}`), are in this
>> * list also, they can be differentiated from initial values by their
>> * type: `LzInitExpr` for the former, and `LzConstraintExpr` for the
>> * latter. If you handle the installation of any instance attributes
>> * in your construct method, you are responsible for dealing with
>> * these "binders" as well. Normally, they will be processed by
>> * LzNode.
>>
>> So, I did a little performance testing
>> (trunk/test/performance/typeof-instance-of.lzx) and found a few
>> potential optimizations:
>>
>> a) typeof func == 'function' is about 2x faster than f instanceof
>> Function.
>>
>> b) typeof seems to be much faster than instanceof. Since many
>> arguments are not LzInitExpr, it might be worth doing this:
>> typeof arg == 'object' && arg instanceof LzInitExpr;
>>
>> instead of just this:
>> txt instanceof LzInitExpr;
>>
>> Here are my numbers for swf8:
>> iterations = 200
>> empty : 6.35us ± 2.23 [5.00..10.00]/100
>> instanceof : 30.25us ± 2.88 [20.00..35.00]/100
>> typeof : 21.05us ± 2.59 [10.00..25.00]/100
>> typeof with instanceof : 30.00us ± 2.25 [25.00..35.00]/100
>> property lookup : 19.60us ± 2.43 [15.00..25.00]/100
>> typeof with instanceof with short circuit: 15.05us ± 0.87
>> [10.00..20.00]/100
>> typeof function : 12.90us ± 2.48 [10.00..15.00]/100
>> instanceof function : 26.40us ± 2.26 [25.00..30.00]/100
>>
>>
>> And for DHTML, firefox OS x:
>> iterations = 200
>> empty : 5.65us ± 1.69 [5.00..10.00]/100
>> instanceof : 29.90us ± 7.85 [15.00..40.00]/100
>> typeof : 17.40us ± 4.23 [10.00..25.00]/100
>> typeof with instanceof : 30.40us ± 3.94 [20.00..35.00]/100
>> property lookup : 15.35us ± 1.78 [10.00..20.00]/100
>> typeof with instanceof with short circuit: 12.75us ± 2.50
>> [10.00..15.00]/100
>> typeof function : 12.40us ± 2.51 [10.00..15.00]/100
>> instanceof function : 19.10us ± 2.29 [15.00..25.00]/100
>>
>> Let me know what you think...
>>
>> --
>> Regards,
>> Max Carlson
>> OpenLaszlo.org
>>
>
--
Regards,
Max Carlson
OpenLaszlo.org
More information about the Laszlo-dev
mailing list