perf: avoid computing paths on each request#15318
Conversation
|
|
|
|
||
| // check if public dir is inside root dir | ||
| const publicDir = normalizePath(server.config.publicDir) | ||
| const rootDir = normalizePath(server.config.root) |
There was a problem hiding this comment.
vite/packages/vite/src/node/config.ts
Lines 490 to 492 in ea6a7a6
vite/packages/vite/src/node/config.ts
Line 738 in ea6a7a6
config.root is already normalized, so we don't need to normalize it here.I think we can normalize the publicDir when we resolve the config as well.
vite/packages/vite/src/node/config.ts
Lines 650 to 656 in ea6a7a6
There was a problem hiding this comment.
Done with config.root. About publicDir, we got hit by it not being normalized here #15317, so I think it is a good idea. But I was thinking we should do this in the next minor or major because some plugins may expect it to not be normalized. Hopefully there aren't many instances like that but better to play safe.
I think that all the directory paths in the resolved config should be normalized and without a trailing slash: root, publicDir, outDir. We should check what we are doing with base. There are a lot of places were we are doing a path.posix.join or similar when we could be directly concatenating the strings if we trust the resolved config.
Description
We should optimize responding from the server as much as possible. For large projects, the time it takes the server to serve already transformed requests will greatly affect reloading time.
This PR avoids normalize paths and path checks that were done on each request. It is safe to cache this in the middleware constructor after #15166
I also moved the warning to another function because it isn't important for the main logic of the handler.
What is the purpose of this pull request?