stylo: Use a SmallVec to accumulate properties when parsing declaration blocks

Assigned to



CSS Parsing and Computation
4 months ago
2 months ago


(Reporter: bholley, Assigned: SimonSapin)


(Blocks: 2 bugs)

Firefox Tracking Flags

(Not tracked)


This should allow us to eliminate realloc overhead, which is ~40ms on the 100x myspace testcase. See bug 1331843 comment 34.

We should of course measure that this does what we want, and that the added memmov traffic to copy the entries off the stack doesn't cancel out the win.
Blocks: 1243581
Note that I did this for selector parsing in bug 1331843, and it was a modest win. We should still investigate for PDB parsing, which is what this bug is about.

Comment 2

2 months ago uses a stack-allocated ArrayVec during property parsing, then calls Vec::reserve before pushing to the Vec inside PropertyDeclarationBlock. This is all per source `name: value;` declaration though, so it only helps with shorthands that expand to many longhands. (`all` being the extreme case.)

The number of longhands a shorthand expands to is known based on only its name, so instead of pushing to PropertyDeclarationBlock at the end of each `name: value` source declaration we could do so at the *start*, only if the ArrayVec doesn’t have enough available capacity. (Plus of course at the end of the block.) Though keeping all the corner cases working correctly may be tricky. (For example more invalid tokens causing the source declaration to be dropped after we’ve already pushed to ArrayVec.)

(By the way, it’d be nice to have better terminology for "a declaration" before v.s. after shorthand expansion.)
You need to log in before you can comment on or make changes to this bug.