Commit 862453c
committed
perf: rework snapshot hot paths
This function was originally using `replace` to unix-ify paths before
then testing against them with `endsWith`.
We can instead use static patterns on the unaltered path regardless of
separator.
This was originally using `split` to "parse" the cache key into a
file/specifier pair.
We don't actually need to do this as we know there's always one
occurrence of `CACHE_KEY_SEPARATOR`. So we can instead just `slice` on
the index of the separator.
Additionally, we only compute any of this the first time we encounter an
unresolved cache entry.
I then noticed that `fileNameWithoutEnding` could be `a` (from
`a.svelte`), for example. This then meant we would delete all cache
entries with specifiers containing `a` (since we did
`specifier.includes(fileNameWithoutEnding)`).
I have changed this to explicitly test for these two cases instead:
- Exact match (i.e. the specifier is exactly `fileNameWithoutEnding`)
- Path-like string includes specifier (`/{fileNameWithoutEnding}.`)
For example, `a.svelte` would become `a`. We then want to check for
`/a.` to be able to match `/a.svelte`, `/a.svelte.js`, etc. Nobody can
import it without a `/` preceding it since then it'd be a bare
specifier.
We currently key by file name and specifier.
It shouldn't be possible for two sibling files to resolve the same specifier
to two different modules.
So it seems like we should be able to key by `dirname(path)` instead.
This means we would cache resolution for entire directories rather than
re-computing it for every file in that directory.
This now uses `slice` on the last separator rather than splitting only
to retrieve the last part.1 parent dec37ea commit 862453c
File tree
3 files changed
+35
-16
lines changed- packages/language-server/src
- plugins/typescript
3 files changed
+35
-16
lines changedLines changed: 11 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
76 | 82 | | |
77 | 83 | | |
78 | 84 | | |
| |||
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
124 | | - | |
125 | | - | |
126 | 130 | | |
127 | 131 | | |
128 | 132 | | |
129 | 133 | | |
130 | 134 | | |
131 | 135 | | |
132 | | - | |
133 | | - | |
| 136 | + | |
| 137 | + | |
134 | 138 | | |
135 | 139 | | |
136 | 140 | | |
137 | | - | |
| 141 | + | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
142 | 146 | | |
143 | 147 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 148 | + | |
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| |||
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
160 | | - | |
| 161 | + | |
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
| |||
Lines changed: 20 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | | - | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
71 | 82 | | |
72 | 83 | | |
73 | 84 | | |
74 | 85 | | |
75 | 86 | | |
76 | 87 | | |
77 | 88 | | |
78 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
79 | 94 | | |
80 | 95 | | |
81 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
64 | 67 | | |
65 | 68 | | |
66 | 69 | | |
| |||
0 commit comments