Author: max
Date: 2007-08-10 14:21:06 -0700 (Fri, 10 Aug 2007)
New Revision: 6010
Modified:
openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/core/LzNode.lzs
openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/LzCSSStyle.js
Log:
Change 20070810-maxcarlson-U by [EMAIL PROTECTED] on 2007-08-10 13:58:38 PDT
in /Users/maxcarlson/openlaszlo/wafflecone
for http://svn.openlaszlo.org/openlaszlo/branches/wafflecone
Summary: More LFC optimization
New Features:
Bugs Fixed: LPP-4414 - Improve startup performance (partial)
Technical Reviewer: promanik
QA Reviewer: ben
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details: LzNode.lzs - Move test for __LZstyleConstraints outside
__LZapplyStyleConstraints() to save method calls. Avoid checking dep.length
twice in applyConstraint().
LzCSSStyle.js - Inline _compoundSelectorApplies() call in
getPropertyValueFor(). Simplify/rename _selectorApplies()
_compoundSelectorApplies() as it now only applies to compound selectors.
LzSprite.as - Avoid sending resource load events for empty resources.
Tests: http://localhost:8080/wafflecone/...silver/main.lzx?lzr=dhtml&lzt=html
shows ~37152 fewer total method calls (from 206356 to 169204). At least 44288
calls to _compoundSelectorApplies() have been eliminated.
http://localhost:8080/wafflecone/test/smoke/smokecheck.lzx passes.
Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/core/LzNode.lzs
===================================================================
--- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/core/LzNode.lzs
2007-08-10 21:13:54 UTC (rev 6009)
+++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/core/LzNode.lzs
2007-08-10 21:21:06 UTC (rev 6010)
@@ -537,14 +537,12 @@
* @keywords private
*/
function __LZapplyStyleConstraints() {
- if (this.hasOwnProperty('__LZstyleConstraints')) {
- var styleConstraints = this.__LZstyleConstraints;
- for ( var k in styleConstraints ) {
- var fn = styleConstraints[ k ];
- var v = fn.call(this);
+ var styleConstraints = this.__LZstyleConstraints;
+ for ( var k in styleConstraints ) {
+ var fn = styleConstraints[ k ];
+ var v = fn.call(this);
// Debug.format("%w[%s] (%#w) %#w -> %#w", this, k, stylemap[k],
this.k, v);
- this.setAttribute(k, v);
- }
+ this.setAttribute(k, v);
}
}
@@ -707,7 +705,7 @@
this.isinited = true;
this.__LZresolveReferences();
- this.__LZapplyStyleConstraints();
+ if (this.__LZstyleConstraints) this.__LZapplyStyleConstraints();
var sl = this.subnodes;
if (sl) {
var i = 0;
@@ -1320,7 +1318,8 @@
* [ this, "x" , myfriend, "width" ]
*/
function applyConstraint ( prop , cfunc, dep ){
- if ( dep.length ){
+ var l = dep.length;
+ if (l){
if ( !this.__LZdelegates ){
this.__LZdelegates = [];
}
@@ -1338,7 +1337,6 @@
// be called more than once in an event chain, because it gets
// a separate delegate for each dependency, and people have
// written code that only works because of this loophole...
- var l = dep.length;
var dp;
for ( var i = 0 ; i < l ; i+=2 ){
var d = new LzDelegate( this , refF );
Modified: openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/LzCSSStyle.js
===================================================================
--- openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/LzCSSStyle.js
2007-08-10 21:13:54 UTC (rev 6009)
+++ openlaszlo/branches/wafflecone/WEB-INF/lps/lfc/services/LzCSSStyle.js
2007-08-10 21:21:06 UTC (rev 6010)
@@ -103,12 +103,45 @@
for ( var i = this._rules.length -1; i >=0; i-- ){
r = this._rules[ i ];
var rp = r.parsed;
- if ( rp.type == this._sel_star ||
+ //inlined: if (rp.type == this._sel_compound &&
this._compoundSelectorApplies( rp, node )) {
+ if (rp.type == this._sel_compound) {
+ var curnode = node;
+ var sindex = rp.length - 1;
+ var firstone = true;
+ var result = false;
+
+ while (curnode != canvas){
+ //recursively loop through selectors, ensuring each
applies to the current node or a parent
+ var nrp = rp[sindex]
+ t = nrp.type;
+
+ if ( t == this._sel_star ||
+ (t == this._sel_id && nrp.id == curnode.id) ||
+ (t == this._sel_tag && (((nrp.classname in lz) &&
(curnode instanceof lz[ nrp.classname ])) || ( (nrp.classname in global) &&
(curnode instanceof global[ nrp.classname ])))) ||
+ (t == this._sel_attribute && curnode[ nrp.attrname
] == nrp.attrvalue) ||
+ (t == this._sel_tagAndAttr && curnode[
nrp.attrname ] == nrp.attrvalue && (((nrp.classname in lz) && (curnode
instanceof lz[ nrp.classname ])) || ( (nrp.classname in global) && (curnode
instanceof global[ nrp.classname ])))) ||
+ (t == this._sel_compound &&
this._compoundSelectorApplies( nrp, curnode, true ))){
+ if ( sindex-- == 0 ){
+ result = true;
+ break;
+ }
+ } else if ( firstone ){
+ //if the last selector doesn't apply, then bail --
we'll
+ //come back for this when we recurse over the
parents in
+ //getPropertyValueFor
+ result = false;
+ break;
+ }
+
+ curnode = curnode.parent;
+ firstone = false;
+ }
+ if (result) rules.push(r);
+ } else if ( rp.type == this._sel_star ||
(rp.type == this._sel_id && rp.id == node.id) ||
(rp.type == this._sel_tag && (((rp.classname in lz) &&
(node instanceof lz[ rp.classname ])) || ( (rp.classname in global) && (node
instanceof global[ rp.classname ])))) ||
(rp.type == this._sel_attribute && node[ rp.attrname ] ==
rp.attrvalue) ||
- (rp.type == this._sel_tagAndAttr && node[ rp.attrname ] ==
rp.attrvalue && (((rp.classname in lz) && (node instanceof lz[ rp.classname ]))
|| ( (rp.classname in global) && (node instanceof global[ rp.classname ])))) ||
- (rp.type == this._sel_compound && this._selectorApplies(
rp, node ))){
+ (rp.type == this._sel_tagAndAttr && node[ rp.attrname ] ==
rp.attrvalue && (((rp.classname in lz) && (node instanceof lz[ rp.classname ]))
|| ( (rp.classname in global) && (node instanceof global[ rp.classname ]))))) {
rules.push(r);
}
}
@@ -125,12 +158,45 @@
for ( var i = pprules.length -1; i >=0; i-- ){
r = pprules[ i ];
var rp = r.parsed;
- if ( rp.type == this._sel_star ||
- (rp.type == this._sel_id && rp.id == node.id) ||
- (rp.type == this._sel_tag && (((rp.classname in lz) &&
(node instanceof lz[ rp.classname ])) || ( (rp.classname in global) && (node
instanceof global[ rp.classname ])))) ||
- (rp.type == this._sel_attribute && node[ rp.attrname ] ==
rp.attrvalue) ||
- (rp.type == this._sel_tagAndAttr && node[ rp.attrname ] ==
rp.attrvalue && (((rp.classname in lz) && (node instanceof lz[ rp.classname ]))
|| ( (rp.classname in global) && (node instanceof global[ rp.classname ])))) ||
- (rp.type == this._sel_compound && this._selectorApplies(
rp, node ))){
+ //inlined: if (rp.type == this._sel_compound &&
this._compoundSelectorApplies( rp, node )) {
+ if (rp.type == this._sel_compound) {
+ var curnode = node;
+ var sindex = rp.length - 1;
+ var firstone = true;
+ var result = false;
+
+ while (curnode != canvas){
+ //recursively loop through selectors, ensuring
each applies to the current node or a parent
+ var nrp = rp[sindex]
+ t = nrp.type;
+
+ if ( t == this._sel_star ||
+ (t == this._sel_id && nrp.id == curnode.id) ||
+ (t == this._sel_tag && (((nrp.classname in lz)
&& (curnode instanceof lz[ nrp.classname ])) || ( (nrp.classname in global) &&
(curnode instanceof global[ nrp.classname ])))) ||
+ (t == this._sel_attribute && curnode[
nrp.attrname ] == nrp.attrvalue) ||
+ (t == this._sel_tagAndAttr && curnode[
nrp.attrname ] == nrp.attrvalue && (((nrp.classname in lz) && (curnode
instanceof lz[ nrp.classname ])) || ( (nrp.classname in global) && (curnode
instanceof global[ nrp.classname ])))) ||
+ (t == this._sel_compound &&
this._compoundSelectorApplies( nrp, curnode, true ))){
+ if ( sindex-- == 0 ){
+ result = true;
+ break;
+ }
+ } else if ( firstone ){
+ //if the last selector doesn't apply, then
bail -- we'll
+ //come back for this when we recurse over the
parents in
+ //getPropertyValueFor
+ result = false;
+ break;
+ }
+
+ curnode = curnode.parent;
+ firstone = false;
+ }
+ if (result) rules.push(r);
+ } else if ( rp.type == this._sel_star ||
+ (rp.type == this._sel_id && rp.id == node.id) ||
+ (rp.type == this._sel_tag && (((rp.classname in lz) &&
(node instanceof lz[ rp.classname ])) || ( (rp.classname in global) && (node
instanceof global[ rp.classname ])))) ||
+ (rp.type == this._sel_attribute && node[ rp.attrname ]
== rp.attrvalue) ||
+ (rp.type == this._sel_tagAndAttr && node[ rp.attrname
] == rp.attrvalue && (((rp.classname in lz) && (node instanceof lz[
rp.classname ])) || ( (rp.classname in global) && (node instanceof global[
rp.classname ]))))) {
rules.push(r);
}
}
@@ -272,47 +338,42 @@
}
-/** @devnote this ideally would be two separate functions, but merging them
- * and inlining the cases of the switch statement is a 2x speedup [awolff]
- * @access private */
-LzCSSStyle._selectorApplies = function ( rp , node ){
- //rp is the parsed selector
- var t = rp.type;
- if ( t == this._sel_star ||
- (t == this._sel_id && rp.id == node.id) ||
- (t == this._sel_tag && (((rp.classname in lz) && (node instanceof lz[
rp.classname ])) || ( (rp.classname in global) && (node instanceof global[
rp.classname ])))) ||
- (t == this._sel_attribute && node[ rp.attrname ] == rp.attrvalue) ||
- (t == this._sel_tagAndAttr && node[ rp.attrname ] == rp.attrvalue &&
(((rp.classname in lz) && (node instanceof lz[ rp.classname ])) || (
(rp.classname in global) && (node instanceof global[ rp.classname ]))))) {
- return true;
- } else if (t == this._sel_compound) {
- var curnode = node;
- var sindex = rp.length -1;
- var firstone = true;
+/** @access private
+ * This is inlined above in getPropertyValueFor() - make sure they stan in
sync
+ */
+LzCSSStyle._compoundSelectorApplies = function (rp , node){
+ var curnode = node;
+ var sindex = rp.length - 1;
+ var firstone = true;
+ var result = false;
- while (curnode != canvas){
- var nrp = rp[sindex]
- t = nrp.type;
+ while (curnode != canvas){
+ //recursively loop through selectors, ensuring each applies to the
current node or a parent
+ var nrp = rp[sindex]
+ t = nrp.type;
- if ( t == this._sel_star ||
- (t == this._sel_id && nrp.id == curnode.id) ||
- (t == this._sel_tag && (((nrp.classname in lz) && (curnode
instanceof lz[ nrp.classname ])) || ( (nrp.classname in global) && (curnode
instanceof global[ nrp.classname ])))) ||
- (t == this._sel_attribute && curnode[ nrp.attrname ] ==
nrp.attrvalue) ||
- (t == this._sel_tagAndAttr && curnode[ nrp.attrname ] ==
nrp.attrvalue && (((nrp.classname in lz) && (curnode instanceof lz[
nrp.classname ])) || ( (nrp.classname in global) && (curnode instanceof global[
nrp.classname ])))) ||
- (t == this._sel_compound && this._selectorApplies( nrp,
curnode ))){
- if ( sindex-- == 0 ){
- return true;
- }
- } else if ( firstone ){
- //if the last selector doesn't apply, then bail -- we'll
- //come back for this when we recurse over the parents in
- //getPropertyValueFor
- return false;
+ if ( t == this._sel_star ||
+ (t == this._sel_id && nrp.id == curnode.id) ||
+ (t == this._sel_tag && (((nrp.classname in lz) && (curnode
instanceof lz[ nrp.classname ])) || ( (nrp.classname in global) && (curnode
instanceof global[ nrp.classname ])))) ||
+ (t == this._sel_attribute && curnode[ nrp.attrname ] ==
nrp.attrvalue) ||
+ (t == this._sel_tagAndAttr && curnode[ nrp.attrname ] ==
nrp.attrvalue && (((nrp.classname in lz) && (curnode instanceof lz[
nrp.classname ])) || ( (nrp.classname in global) && (curnode instanceof global[
nrp.classname ])))) ||
+ (t == this._sel_compound && this._compoundSelectorApplies( nrp,
curnode, true ))){
+ if ( sindex-- == 0 ){
+ result = true;
+ break;
}
+ } else if ( firstone ){
+ //if the last selector doesn't apply, then bail -- we'll
+ //come back for this when we recurse over the parents in
+ //getPropertyValueFor
+ result = false;
+ break;
+ }
- curnode = curnode.parent;
- firstone = false;
- }
+ curnode = curnode.parent;
+ firstone = false;
}
+ return result;
}
/** @access private */
_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins