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(kit, schema): measure module setup timings #18648
Conversation
Β Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
Co-authored-by: SΓ©bastien Chopin <seb@nuxt.com>
It seems that using an anonymous module in the config does not trigger a warn: export default defineNuxtConfig({
modules: [
async () => {
// wait 2 sec
await new Promise(resolve => setTimeout(resolve, 2000))
}
]
}) I guess it's safe to ignore but we should advice to use import { defineNuxtModule } from '@nuxt/kit'
export default defineNuxtConfig({
modules: [
defineNuxtModule({
meta: {
name: 'my-module'
},
async setup () {
// wait 2 sec
await new Promise(resolve => setTimeout(resolve, 2000))
}
})
]
}) |
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.
Looks good to me! Waiting for @danielroe review as well and @antfu regarding devtools integration
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.
LGTM. Should we document it somewhere (besides auto-generated docs)?
I guess in #18551 |
PR looks good overall for timing. My two cents:
Consider the debug output atm. Context is lost without knowing what module setup is taking place. It would be good to add a debug on the start of module setup and on the finish. There are a couple of modules that do globs and they have a habit of accidentally scanning the entire node_modules and stalling indefinitely. (pinceau, windicss, etc). Or making network requests which are using large timeouts.
I think this just encourages module authors to "hide" logic that takes more than 1s within hooks, making it hard to debug, so I am against this (unless debug is enabled). |
Completely agree with you on this @harlan-zw |
@pi0 feel free to let me know if I can be helpful here π |
I have made a few changes. And also increased the minimum amount to 5 seconds which is unlikely to happen unless a module is doing something really wrong in which case, "end user" should be aware of why their development experience is slow. And also default hook logs, we have explicit module name as part of warning message so it is tracable. I think anyway using this new exported meta devtools can give better experience. And we might try it for a while across ecosystem to first find the evil and decide to not warn if there are modules that absolutely cannot be optimized! But without a small push to the ecosystem and user awareness by testing against different environments, it is unlikely we could ever find those kind of modules. |
This approach seems good to me. π¨ Note to readers: I think it is not too strong to say we are now engaged in a fight against evil across the galaxy. π¨ |
π Linked issue
resolves #15739
β Type of change
π Description
ModuleReturn
interface for Nuxt modules withtimings
subkey_installedModules
π Checklist