mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
When parsing block contents, the CSS parser speculatively tries to parse each item as a declaration first. If that fails, it restores the token position and tries again as a qualified rule. This means every qualified rule inside an at-rule block (e.g. @layer, @media) gets parsed twice: once as a failed declaration (which consumes all tokens via consume_the_remnants_of_a_bad_declaration), and then again successfully as a rule. Add a lookahead that checks for the `ident whitespace* ':'` pattern before attempting declaration parsing. Since declarations must start with this pattern per spec, we can skip the attempt entirely when it doesn't match and go straight to qualified rule parsing. This is a massive win on large Tailwind CSS stylesheets (like the one used by chatgpt.com) where thousands of rules inside @layer blocks were being double-parsed. On a 1.2MB Tailwind v4 stylesheet, parse time goes from ~2000ms to ~95ms (21x speedup).