selectoplasm

Worker Performance

Since your web worker will be called any time the user changes an input in the Plugin Manager, it's a good idea to pay attention to performance. Ideally you can keep the worker's runtime to less than 16ms, as this will keep your updates running at 60fps.

The easiest way to ensure your plugin is performing reasonably is to combine any loops you have into a single loop. During development, it's obviously easier to write separate functions, but once you're happy with the way your plugin works, if you have multiple loops, it's recommended to rewrite your plugin so that the worker loops as few times as possible.

It would take a fairly complex plugin to still have trouble after consolidating loops. If you find yours has gotten to this point, you might want to consider splitting it into separate plugins. Remember, you can use design tokens from one plugin in another, since they all end up in the same stylesheet library in Selectoplasm. Just be sure to note that in your plugin's README.

The official plugins Colors-Oklch and Theme are an example of two plugins that work together.

Also, a quick note about what happens when a user makes several quick changes in quick succession, for instance, when dragging a slider.

If the user changes your plugin config while your plugin's worker is running, Selectoplasm buffers the new config and waits for the worker to finish before sending it. If the user makes another change while there's a buffered config, Selectoplasm discards the buffered config and buffers the more recent config.

So in the worst case scenario, your plugin's worker might run twice in succession. Something to keep in mind.