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(nuxt): support parallel plugins #20460
Conversation
Β Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
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.
ππΌ
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.
I love this! A couple of thoughts:
- Do you think we would still need to respect plugin ordering? In this case, we would need to await plugins (even parallel ones) before proceeding to the next 'chunk' of plugins. Another plugin (deliberately marked later in order) may be relying on every plugin previously having been run first.
- ...which brings me to another point. I wonder if we can automatically enable parallelism for plugins that have specified their order, for example. (So all
order: 20
plugins would run at the same time unless explicitly disabled.) User plugins (order: 0
) would be exempt from this default behaviour. (Counter-point: this may be considered to be a breaking change.)
Later on, I do hope we can make plugin ordering more deterministic at build-time, extracting plugin order and maybe even allowing specified dependsOn
with the new plugin name option.
I guess we can document about using |
This sounds a bit tricky. I think ideally for this optimization to take good effect, we should make as much parallelism as possible, so I kinda feel make enable parallelism for most of the plugins would be nice (regardless of the breaking change concern). I am not very should of grouping by order, as the I am also not very sure how often would plugins rely on each other, or how often would an async plugin requires to be blocking. Maybe |
I agree that dependency graph for hooks is probably best solution for complex setups and ordering. Running parallel plugins at end makes sense and is elegant:) |
Just a quick thought. I do not know how exactly async function simulatePlugin(shouldThrow = false, delayMs = 100) {
await new Promise((resolve) => setTimeout(resolve, delayMs))
if (shouldThrow) { throw new Error() }
}
async function executePlugins(plugins) {
const parallels = []
for (const plugin of plugins) {
const promise = plugin.run()
if (plugin.parallel) { parallels.push(promise) }
else { await promise }
}
await Promise.all(parallels)
}
await executePlugins([
{ run: () => simulatePlugin() },
{ run: () => simulatePlugin(true), parallel: true },
{ run: () => simulatePlugin() },
{ run: () => simulatePlugin() },
]) |
π Linked issue
β Type of change
π Description
It's very convenient that plugins support async functions. However, sometimes it could become a pitfall that users might put too much logic inside them, which leads to slow app initialization. For example, In some cases, a plugin might wait to load some resources like i18n messages. Currently, we execute the plugins one by one sequentially - causing the entire App to stay idle, waiting for the request.
Here is what we had in Elk:
π Checklist