msg() function in core.js thrashes style information in a loop
Issue #101
resolved
The function has this bit:
dojo.forEach(dojo.query("*", gameLog), function (entry, i) {
if (i > 25) {
var opacity = dojo.getStyle(entry, "opacity");
dojo.setStyle(entry, "opacity", opacity - 0.033);
}
});
this is an instance of the antipattern where style information is modified and then queried in a loop, forcing a recomputation at every query, which takes nontrivial time, because style information has been modified in the interim.
Why is the query needed at all? We know that the last time msg
was called the opacity was set to 1 for all the things that are currently at i <= 26
, and for i
larger than that it decreases by 0.033 each time. So the desired opacity to set can just be directly computed from i
as 1 - (i-25)*0.33
, I would think.
Comments (4)
-
-
reporter I think that should be equivalent to what's there now but faster, yes.
-
It may work^^
-
- changed status to resolved
optimization of gameLog fixes
#101→ <<cset d93d27855267>>
- Log in to comment
You suggest something like that ?