niklasvh/html2canvas — pull request #270 by ssafejava (2013-09-18 05:53:26+00:00)
Title: Speed parsing by as much as 50% & add async parsing option.

I have been considering using html2canvas as an error reporting utility to send a page state screenshot on a JS error.

Unfortunately the current master is a little too slow for my tastes, so I spent some time with the profiler and discovered two major improvements that could be made:

1. All calls to html2canvas look asynchronous - if parsing is actually asynchronous, the browser won't lock up during parsing, which would make it far less intrusive.
2. Processing of pseudo elements, when shut off, speeds parsing by 2 to 3x.

This PR addresses both items. You can see more detailed information in the individual commit messages.

Additionally this PR fixes a rendering bug regarding `:before` pseudo elements, which were incorrectly being appended before the element affected, when they should have been inserted as the first child.

A few timeline screenshots of the difference:

Current master (806cd6047446c68a) - notice the volume of purple (restyles/relayouts) caused by inefficient pseudo element parsing.
![Slow Rendering](http://i.imgur.com/ALcMuouh.png)

This patch - nearly 50% faster, far less purple.
![Faster Rendering](http://i.imgur.com/PHdq2c4h.png)

This patch with {async: true} - slower than above, still faster than master & doesn't freeze the browser.
![Async Rendering](http://i.imgur.com/EoeEicGh.png)