mbostock/d3 — pull request #424 by jasondavies (2011-12-31 10:14:21+00:00)
Title: Optimise selection.order.

A small optimisation: only call insertBefore() if node.nextSibling isn't already what we want, so that document nodes that are already in the correct order can be skipped.

A rudimentary benchmark in Chrome on 1,000 nodes looks promising: roughly 7x faster when ordering an unchanged data array. Negligible impact on ordering based on a randomised data array due to the extra conditional check: around 1% overhead for the same benchmark (30μs per call).

I got similar results in Firefox.