Skip to content

Thoughts on thread-unsafe plugin usage patterns #5

@yyx990803

Description

@yyx990803

Context: https://github.com/sapphi-red/parallel-js-plugin-experiment/blob/main/research-for-design.md

  • It's great that many common caes can be solved with module.meta!

  • Agree that we should make chunk.meta work like module.meta and maybe also need something like currentBuild.meta (exposed via plugin this context maybe?), essentially officially supported mechanisms for storing thread-safe data.

  • Regarding plugin-vue - we do have the option to re-design plugin-vue to be more threading-friendly. But for now, cache-miss is not the end of the world.

  • We don't need to worry about @rollup/plugin-node-resolve or @rollup/plugin-commonjs - these are built-in features of Rolldown so they are not going to be needed anyway. Similar for @rollup/plugin-replace, vite:esbuild, vite:esbuild-transpile etc.


How can we handle (A7) pattern in parallel plugins? Also for builtin rust plugins.

This seems to be the biggest blocker. I think we may need to identify cases of:

  1. Using api for exposing / mutating serializable options
  2. Using api for injecting functions (e.g. sveltePreprocess)

(1) Seems to be straightforward, but (2) is going to be problematic. Can you link to some examples of how Qwik uses this pattern?

How can we handle (A8) pattern?

I think we'll have to enforce serializable config formats (I believe both PostCSS and Babel supports that, i.e. specifying plugins via package names so the loading of the plugin is deferred to be controlled by the tools) - luckily should be less of an issue when users move towards Lightning CSS and Oxc for the transforms?

Re simple functions in configs - we might be able to serialize that? But maybe this will just be a hard limitation.

How can we handle (A9) pattern?

vite-plugin-inspect may have to be implemented as a built-in. This should not be common.

How can Vite use Rolldown? ((A10) pattern)

Not sure if I understand the issue with (A10a) - couldn't Rolldown just ignore those hooks like Rollup does? For example, configResolved is called by Vite during config resolution and don't really need to be parallelized.

My general thought on Vite internal plugins is that Rolldown will expose a "plugin container" API - initially this can be a Node.js API where Vite core use to replace the current PluginContainer implementation, but at a later stage we introduce a small Rust core in Vite which uses Rolldown as a dependency - the PluginContainer will then be used via Rust APIs and have as many internal plugins Rustified as possible.

How well does vitejs/vite#16089 work with parallel plugins?

We will need input from @patak-dev and @sheremet-va on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions