3 ms·
Parsing is a really difficult-to-parallelize task. There's no obvious simple way to chunk up the task, since a `{` at line 1 might affect the parsing of a const
by mort96 4y ago
Parsing is a really difficult-to-parallelize task. There's no obvious simple way to chunk up the task, since a `{` at line 1 might affect the parsing of a construct on line 100000.
What you could conceivably do is to have a very simple parser whose only job is to have just enough understanding of CSS to be able to split the CSS document into chunks, and then have a proper parser which works in parallel on the chunks produced by the first parser. I can't imagine this would be faster on most code though, considering how simple the full CSS parser is today, and it still requires a single thread which scans through and parses the entire CSS document.
Regardless, browsers are already really multi-threaded. When you parallelize parsing in this way, even if parsing gets a bit faster in isolation, you're increasing the amount of computation necessary to parse the CSS (i.e spending 1 second on one core is less computational work than spending 0.5 seconds on 4 cores). Your parallel CSS parsing will be taking cycles away from HTML parsing and javascript execution.