jinzhu/vrome — pull request #119 by kezabelle (2012-03-15 21:34:03+00:00)
Title: Speed up the display of link hints.

Currently, on my aging netbook, hitting ```f``` while on [reddit](http://reddit.com) takes between 1500-2500 ms to paint the links yellow.

Initially, I expected the constant calls to ```isElementVisible``` to be where most of the work was spent. It turns out that it's not the calculations that are slow, it's the constant painting & reflowing that goes on when lots of links are present. To solve this, in 7a6121a1 I've introduced a document fragment ([basically a screen buffer](http://code.google.com/speed/articles/javascript-dom.html)) which has all the `````` appended into it in the loop, and then, once the loop is finished (and all links are hinted), the fragment is appended back into the main ```

```, triggering just one paint/reflow action.

This, alone, reduced my average timing from 2400~ms to 200~ms, which is surprisingly substantial.

At the same time, I've moved the calculation for the ```win_top``` and ```win_left``` offsets out of the loop, so they're only set once, because they shouldn't be changing arbitrarily in the middle of that loop, I don't think. That's commit f40e6547

Finally, in 8b502c96, a minor tweak that shouldn't hurt: All the for loops involved in hinting have their iterator lengths pre-calculated, rather than on each iteration.