dim icon indicating copy to clipboard operation
dim copied to clipboard

Design a plugin system.

Open vgarleanu opened this issue 3 years ago • 9 comments

vgarleanu avatar Mar 23 '21 19:03 vgarleanu

Rhai looks like an interesting use case for user scripted plugins.

mental32 avatar Mar 24 '21 22:03 mental32

Rhai looks really nice. This could definitely be used for plugins, however I think we should still look into using wasm instead.

vgarleanu avatar Mar 26 '21 18:03 vgarleanu

We could definitely use CGlue here

vgarleanu avatar Nov 28 '21 00:11 vgarleanu

WASM would allow plug-ins to use various languages, with near native performance. However, there are some limitations on WASM APIs. As it stands WASM bindings are limited to primitive numeric types and arrays of them. That might be OK for streaming audio or video, but it could be very awkward for complex structs. Also, calling to or from wasm requires all data to be copied to/from the wasm sandbox memory. Wasm would be great. These are just some things to consider.

rich-murphey avatar Nov 28 '21 04:11 rich-murphey

There are some improvements to wasm-bindgen that allow passing arbitrary types between the host and a wasm guest. Serde is used to serialize the data during transfer between them. It's described here: Arbitrary Data with Serde.

rich-murphey avatar Jan 09 '22 22:01 rich-murphey

There are some roadblocks to using the serde feature of wasm-bindgen. It creates a cyclic dependency on aHash whenever another crate (such as sqlx, Hashbrown or others) also depends on aHash. . That discussion has a recommendation, "I would recommend to basically avoid the serde features in wasm-bindgen.".

There is a lot of interest in resolving the issue. For the moment it may significantly limit the dependencies in the host application. Sounds like it might be resolved eventually.

rich-murphey avatar Jan 12 '22 17:01 rich-murphey

I've thought quite a bit about how to write a extensible plugin system, and I think the best approach here is a RPC based plugin system where each plugin lives as its own process and manages its own resources and environment. The plugins could communicate with Dim using something like tarpc or capnproto. The maintenance burden would likely be the same as managing a C-ffi or wasm shim. We could also easily sandbox these plugins.

In regards to what kind of features I'd like to support, I'd like to add the ability for plugins to hook REST API calls as in the future I'd like to have a plugin that essentially would extend or replace the current streaming APIs with smarter versions with more features.

I'd also like to add the ability for plugins to register UI elements, so we could allow plugins to have their own dashboards or settings if necessary. This would most likely be only available on the Web-UI.

vgarleanu avatar Jan 12 '22 23:01 vgarleanu

Binary RPCs sounds very efficient, leaving the door open for low latency interaction. Sounds great!

rich-murphey avatar Jan 13 '22 07:01 rich-murphey

This is what is done for the Terraform plugin infrastructure. I would suggest taking a look at their writeup and implementation for inspiration.

Additionally, gRPC seems like a great approach for this. Here is a great example for reference.

DesignsWithDavid avatar Feb 09 '22 19:02 DesignsWithDavid