feat(kit, schema): measure module setup timings#18648
Conversation
|
|
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))
}
})
]
}) |
atinux
left a comment
There was a problem hiding this comment.
Looks good to me! Waiting for @danielroe review as well and @antfu regarding devtools integration
TheAlexLichter
left a comment
There was a problem hiding this comment.
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
ModuleReturninterface for Nuxt modules withtimingssubkey_installedModules📝 Checklist