Sunday, May 6, 2007

Delayed execution idea scrapped, but the optimizations stayed

After some more thoughts, delayed execution is found to be stupid. It requires the web developer to change their code to get the benefits, and it sometimes breaks your application.

What's this delayed execution stuff about originally? It's actually a trick to get around browser inefficiencies in rendering DOM nodes with CSS attributes.

Consider the following two code snippets:

// placing 5000 "Hello World" messages in random positions
for(var i=0;i<5000;i++)
{
var node = document.createElement("div");
node.appendChild(document.createTextNode("Hello World!"));
document.body.appendChild(node);
node.style.position = "absolute";
node.style.left = parseInt(Math.random() * 800) + "px";
node.style.top = parseInt(Math.random() * 800) + "px";
}

// placing 5000 "Hello World" messages in random positions
for(var i=0;i<5000;i++)
{
var node = document.createElement("div");
node.appendChild(document.createTextNode("Hello World!"));
node.style.position = "absolute";
node.style.left = parseInt(Math.random() * 800) + "px";
node.style.top = parseInt(Math.random() * 800) + "px";
document.body.appendChild(node);
}

Both code snippets place 5000 randomly positioned "Hello World!" messages in the browser window. The two code snippets differ only in the placement of the document.body.appendChild() line. Running the first code snippet in Firefox can take 1 minute or more, but running the second one takes only a few seconds. The second code snippet provides a more than 10x speedup compared to the first code snippet.

Similar phenomenon can be observed in Internet Explorer also, but only with much more complicated logic, so we'll not go over that. But anyway, the moral of the story is, modifying some CSS attributes (especially positioning attributes) is harmful after the DOM node is already visible.

So what did the scrapped delayed execution idea has to do with these browser weirdnesses? The delayed execution idea was meant to help in batch widget creation and batch CSS style manipulations. e.g. when you're creating 100 widgets in a single pass. It speeds up widget creation or CSS style manipulation by making a common ancestor DOM node of the widgets being manipulated/created invisible before executing the performance sensitive code, and making the ancestor node visible again after execution.

Sounds like a hack - yes it is a hack. It sometimes breaks your application code, it requires you to change your application code to use it. But as shown in the videos, it worked.

Now, the hack is scrapped, before it is even released. And that's because we've got a more consistent way of implementing the same optimization in WT Toolkit, without the need of using hacks.

So what do we have for 0.3.3 now:

  1. Massively increased widget creation performance in Internet Explorer, without needing the developer to change a single line of code.
  2. No performance improvement in Firefox if you don't change your application code... Oops?! But hey, that would be the same if we implemented the delayed execution hack.

But what if you want to make your WT Toolkit application run faster in Firefox? Just pass null as the parentWidget argument to the widget constructor as much as possible, and add the widget to the document tree only after you've done all the CSS manipulations.

Say, if you have

var n = new wtButton(myParent, "Yes!");
n.setAbsolutePosition(x, y);

Then, the optimized version would be

var n = new wtButton(null, "Yes!");
n.setAbsolutePosition(x, y);
myParent.addWidget(n);

Actually, you can perform the manual optimization with WT Toolkit 0.3.2 too.

61 comments:

Anonymous said...

Кстати, не зря блогоньюс называется местом сбора всего самого увлекательного. [URL=http://blogonews.net]Интересный сайт[/URL] - несомненно правильное название сайта.

Anonymous said...

xanax without prescription legal to order xanax online - percocet xanax high

Anonymous said...

tramadol 50 mg what does tramadol 50 mg look like - buy tramadol online florida

Anonymous said...

buy tramadol online buy tramadol overnight delivery no prescription - buy tramadol online overnight shipping

Anonymous said...

order xanax xanax clearance drug screen - xanax side effects shaking

Anonymous said...

xanax online prescription there 4mg xanax bars - xanax pills g3719

Anonymous said...

buy tramadol online rx tramadol sr - 100 mg - tramadol 50 mg snorting

Anonymous said...

where can i buy xanax online legally xanax 2mg oval - xanax 031 side effects

Anonymous said...

generic xanax generic xanax good xanax - order my xanax prescription online

Anonymous said...

tramadol 50mg buy tramadol in europe - ultram tramadol forum

Anonymous said...

buy tramadol online tramadol ultram er - tramadol euphoria dose

Anonymous said...

buy carisoprodol buy soma carisoprodol online - carisoprodol soma watson brand

Anonymous said...

buy tramadol online tramadol dosage sizes - buy tramadol online overnight

Anonymous said...

xanax online pictures of generic xanax bars - buy xanax san francisco

Anonymous said...

buy tramadol online tramadol purchase online no prescription - tramadol yellow and green capsule

Anonymous said...

xanax mg buy generic xanax no prescription - buy xanax 2mg bars online

Anonymous said...

buy carisoprodol carisoprodol hair drug test - carisoprodol 350 mg for pain

Anonymous said...

xanax online xanax 4mg pill - xanax and alcohol lethal

Anonymous said...

carisoprodol online carisoprodol overdose emedicine - drug drug interactions carisoprodol

Anonymous said...

buy tramadol with mastercard order tramadol visa - tramadol addiction after 1 week

Anonymous said...

xanax online results xanax overdose - zolpidem xanax overdose

Anonymous said...

buy carisoprodol carisoprodol 350 mg interactions - carisoprodol 350 mg pill

Anonymous said...

carisoprodol 350 mg carisoprodol pharmacokinetics - carisoprodol 350 mg muscle relaxer

Anonymous said...

buy tramadol online no prescription tramadol 50mg tablets ingredients - tramadol for dogs mg

Anonymous said...

buy cialis online usa buy generic viagra cialis online - buy cialis online us

Anonymous said...

tramadol 50 mg cheap tramadol online cod - tramadol and us overnight no prescription

Anonymous said...

cialis online best way buy cialis online - cialis price daily use

Anonymous said...

buy cialis online generic cialis best price - cialis daily wholesale

Anonymous said...

buy cialis online cialis kopen - cialis generic no prescription

Anonymous said...

buy cialis online order viagra cialis online - buy cialis drugstore

Anonymous said...

buy cialis prescription online cialis daily tadalafil - cialis 20 reviews

Anonymous said...

cialis online buying cialis online forum - cialis online in usa

Anonymous said...

xanax online generic xanax pill identifier 029 - xanax xr 1mg price

Anonymous said...

cialis online cialis price pharmacy - cialis coupon

Anonymous said...

learn how to buy tramdadol can you buy tramadol online no prescription - tramadol 319 high

Anonymous said...

learn how to buy tramdadol buy tramadol australia - tramadol online no prescription overnight cod

Anonymous said...

buy discount tramadol how to order tramadol - tramadol hcl xr

Anonymous said...

learn how to buy tramdadol tramadol ultram seizures - tramadol 50mg for pets

Anonymous said...

buy tramadol tramadol dosage dogs - buy tramadol online saturday delivery

Anonymous said...

buy tramadol online no prescription tramadol online mastercard - tramadol 50 mg tab amne

Anonymous said...

buy tramadol buy tramadol online with credit card - tramadol online american express

Anonymous said...

buy tramadol cod tramadol in pregnancy - where to buy tramadol forum

Anonymous said...

buy tramadol tramadol buy florida - tramadol ingredients side effects

Anonymous said...

tramadol 100mg buy tramadol online eu - best online pharmacy tramadol

Anonymous said...

buy tramadol online cheap buy tramadol online prescription - buy tramadol 99

Anonymous said...

buy tramadol buy tramadol overnight no prescription - buy-tramadol-online.org

Anonymous said...

buy tramadol tramadol for dogs effects - tramadol 50mg 627

Anonymous said...

buy ativan online ativan getting high - 8 ativan

Anonymous said...

http://blog.dawn.com/dblog/buy/#56932 order tramadol cod next day delivery - tramadol withdrawal wellbutrin

Anonymous said...

ways to buy ativan online ativan withdrawal caffeine - ativan high blood pressure

Anonymous said...

buy tramadol cheap 100mg tramadol - tramadol hydrochloride capsules 100 mg

Anonymous said...

ativan pharmacy ativan withdrawal emedicine - ativan overdose level

Anonymous said...

http://staam.org/#36750 tramadol online pharmacy no prescription needed - tramadol itching

Anonymous said...

buy tramadol online tramadol hydrochloride 50mg dosage - buy ultram tramadol online

Anonymous said...

buy xanax online buy xanax online cod - generic xanax pill description

Anonymous said...

buy tramadol online tramadol dosage get high - buy tramadol online prescription

Anonymous said...

buy xanax online xanax and alcohol teenagers - xanax you buy online real

Anonymous said...

alprazolam xanax 2mg too much - xanax and alcohol withdrawal symptoms

Anonymous said...

buy xanax online xanax overdose kill - buy generic xanax no prescription

Anonymous said...

buy xanax online cost of generic xanax at walmart - 2mg xanax and 2 beers

Anonymous said...

buy xanax online cod side effects from xanax drug - xanax xr 3mg