puppetlabs/geppetto — pull request #26 by thallgren (2014-08-18 07:51:51+00:00)
Title: (GEP-165) Speed up the CSS Dom formatter

Formatting large files is a fairly slow process. On older laptops
it can take several seconds to format a moderately large manifest.
Profiling shows that the culprit is in Select.NodeSelector.match().

This commit will speed things up a lot. The main reason for the
speed-up is that the constant predefined EnumSet instances are no
longer wrapped in a Collections.unmodifiableSet() since that
wrapper effectively removes all benefits of using EnumSets. The
underlying cause can be found in the RegularEnumSet and the
first two lines of the containsAll() method:

public boolean containsAll(Collection c) {
if (!(c instanceof RegularEnumSet))
return super.containsAll(c);

Wrapping the EnumSet will result in super.containsAll(c) which in
turn will do a sequential iteration over the elements and call the
contains() method on each. The contains() method in turn will check
the class of the element befor checking if the element bitmap overlaps.

Compare this to just comparing the 'elementType' contained in both
sets once and then checking for bitmap overlap.