Commit b368b40
authored
Improve utility lookup performance when using v4 (#1509)
Companion PR to tailwindlabs/tailwindcss#19405
The aim of this PR is to improve the performance around looking up /
compiling candidates into utilities when using v4.
It does this in three stages:
1. For earlier versions (v4.0–v4.1.17) we swap out PostCSS (mostly) with
our own CSS parser. The implementation is tailored to improve
performance and memory usage for how we use it. This also means I've
been able to optimize how we walk the AST and remove mutations in many
places.
There *are* still some internal APIs that use PostCSS because they
interface with multiple versions of Tailwind CSS. These still use
PostCSS and we translate our AST into a PostCSS AST for these cases.
Eventually these APIs will also be converted to use our internal CSS AST
directly — we'll support old versions by converting *from PostCSS* to
our internal AST — that is for a future PR.
2. For new enough versions, since our AST here mirrors the one in
Tailwind CSS, we can use the nodes directly from Tailwind CSS itself
instead of generating the code inside Tailwind CSS, serializing to a
string, and then finally re-parsing. This is exactly what the
`candidatesToAst` API enables (will ship in Tailwind CSS v4.1.18).
3. A large portion of the candidate compiling perf is spent on color
lookups. The above will help with that significantly but there's still a
large amount of time analyzing declaration values for colors. This PR
replaces our unwieldy color regex to pick out potential colors with a
fine tuned parser.
This speedup gives us a good bit more headroom for re-enabling mask
utility color swatches. The overhead from parsing an extra 5k utilities
is still too significant but it is now *much* lower than before. The
next big improvements will need to happen in core.1 parent 29eab26 commit b368b40
File tree
24 files changed
+2151
-208
lines changed- packages
- tailwindcss-language-server
- src/util/v4
- tailwindcss-language-service/src
- css
- diagnostics
- util
- v4
- vscode-tailwindcss
- src
24 files changed
+2151
-208
lines changedLines changed: 17 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
| 228 | + | |
237 | 229 | | |
238 | | - | |
| 230 | + | |
239 | 231 | | |
240 | 232 | | |
241 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
242 | 237 | | |
243 | 238 | | |
244 | 239 | | |
245 | 240 | | |
246 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
| 253 | + | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
| 266 | + | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
| 269 | + | |
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | 274 | | |
281 | 275 | | |
282 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
| |||
Lines changed: 49 additions & 42 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
2296 | 2298 | | |
2297 | 2299 | | |
2298 | 2300 | | |
2299 | | - | |
| 2301 | + | |
2300 | 2302 | | |
2301 | 2303 | | |
2302 | 2304 | | |
2303 | 2305 | | |
2304 | | - | |
2305 | | - | |
2306 | | - | |
2307 | | - | |
2308 | | - | |
2309 | | - | |
2310 | | - | |
2311 | | - | |
2312 | | - | |
2313 | | - | |
2314 | | - | |
2315 | | - | |
2316 | | - | |
2317 | | - | |
2318 | | - | |
2319 | | - | |
2320 | | - | |
2321 | | - | |
2322 | | - | |
2323 | | - | |
2324 | | - | |
2325 | | - | |
2326 | | - | |
2327 | | - | |
2328 | 2306 | | |
2329 | 2307 | | |
2330 | 2308 | | |
| |||
2334 | 2312 | | |
2335 | 2313 | | |
2336 | 2314 | | |
2337 | | - | |
2338 | | - | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
2339 | 2323 | | |
2340 | | - | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
2341 | 2344 | | |
2342 | 2345 | | |
2343 | 2346 | | |
2344 | 2347 | | |
2345 | | - | |
2346 | | - | |
2347 | | - | |
2348 | | - | |
2349 | | - | |
2350 | | - | |
2351 | | - | |
2352 | | - | |
2353 | | - | |
2354 | | - | |
2355 | | - | |
2356 | | - | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
2357 | 2360 | | |
2358 | 2361 | | |
2359 | 2362 | | |
| |||
2363 | 2366 | | |
2364 | 2367 | | |
2365 | 2368 | | |
2366 | | - | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
2367 | 2373 | | |
2368 | 2374 | | |
2369 | 2375 | | |
| |||
2373 | 2379 | | |
2374 | 2380 | | |
2375 | 2381 | | |
| 2382 | + | |
2376 | 2383 | | |
2377 | | - | |
| 2384 | + | |
2378 | 2385 | | |
2379 | 2386 | | |
2380 | 2387 | | |
| |||
0 commit comments