-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: server middleware graph #67
Conversation
Marking as draft until Vite shipped it. Ideally, we should also have some logic to hide the tab when running on older vite that does support it. |
Vite would not expose a public API for server-side related perfs after discussion in vitejs/vite#12787, there is no way for vite-plugin-inspect to get the server start-up time, dependencies scanning time, pre-bundle time... but luckily we can get the middleware resolving time via |
serverPerf.middleware![url] = [] | ||
|
||
// @ts-expect-error handle needs 3 or 4 arguments | ||
await (middlewareArgs.length === 4 ? handle(err, req, res, next) : handle(req, res, next)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you help review the middleware timing logic? @sapphi-red @bluwy @patak-dev thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you explain a bit more what is self
here? I'm lost why it needs to be computed at this point, seems to be the same info you have in total
and could check the full array later 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider it as something like self time
& total time
in cpuprofile. Here total
means the middleware execution total time and self
equals total
minus the next()
middleware's total
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. Makes sense, I wasn't clearly thinking in the next()
recursion here.
Maybe to avoid race conditions the best would be to avoid computing self
until you have the complete array with total times. Only keeping each total
is enough, and later you can compute them knowing all the values are there. But this looks good to me 👍🏼
const total = Date.now() - start | ||
const metrics = serverPerf.middleware![url] | ||
|
||
// middleware selfTime = totalTime - next.totalTime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should read prev
here, no?
// middleware selfTime = totalTime - next.totalTime | |
// middleware selfTime = totalTime - prev.totalTime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's next()
totalTime, thinking about the onion model.
I met the negative time before, I think it's due to the |
Description
Support showing vite dev server middleware perfs
Linked Issues
This PR depends on vitejs/vite#12787Additional context