Commit 29eab26
authored
Improve performance in large files (#1507)
There are two performance improvements here that both come down to
caching:
- We call `indexToPosition` *a lot*. Every time this is called it takes
the string passed in and re-computes the indices every time. There's no
need for this so we have a small, module-level LRU cache to store the
data.
This should eventually be replaced with parsing and storing data up
front when files are edited instead of just doing this whenever we
receive a request. That would negate the need for a module-level cache.
- We call `compile()` and `candidatesToCss` *a lot* as well. This is
expected but 90% of the time the classes passed in have already been
seen. We take the generated CSS and convert to a PostCSS node because a
lot of the implementation uses that internally. There's no need to go
through the whole parse -> serialize -> re-parse routine like we are.
I've opted to store the compiled PostCSS roots on the
`designSystem.storage` object (which will be created when it doesn't
exist on old versions) and we'll return clones of those objects every
time (since they may get mutated).
With this there's only one large-ish block in a left-heavy profile:
`findClassListsInHtmlRange`. That is mostly related to the class
attribute lexer. Fixing it will require us to scan document and store
info about them when they change. We shouldn't need to run the class
attribute lexer if the document hasn't changed. Fixing this will require
some more work though.
Fixes #15031 parent e586933 commit 29eab26
File tree
4 files changed
+49
-9
lines changed- packages
- tailwindcss-language-server/src/util/v4
- tailwindcss-language-service/src/util
- v4
- vscode-tailwindcss
4 files changed
+49
-9
lines changedLines changed: 30 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
215 | 216 | | |
216 | 217 | | |
217 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
218 | 224 | | |
219 | 225 | | |
220 | 226 | | |
| |||
227 | 233 | | |
228 | 234 | | |
229 | 235 | | |
230 | | - | |
231 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
232 | 242 | | |
233 | 243 | | |
234 | | - | |
235 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
236 | 251 | | |
237 | 252 | | |
238 | | - | |
| 253 | + | |
239 | 254 | | |
240 | 255 | | |
241 | | - | |
| 256 | + | |
| 257 | + | |
242 | 258 | | |
243 | | - | |
| 259 | + | |
244 | 260 | | |
245 | 261 | | |
246 | 262 | | |
247 | 263 | | |
248 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
249 | 272 | | |
250 | 273 | | |
251 | 274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
591 | 591 | | |
592 | 592 | | |
593 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
594 | 605 | | |
595 | | - | |
| 606 | + | |
| 607 | + | |
596 | 608 | | |
597 | 609 | | |
598 | 610 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
0 commit comments