google / neuroglancer

WebGL-based viewer for volumetric data
Apache License 2.0
1.03k stars 286 forks source link

Consider using SolidJS #511

Open jbms opened 6 months ago

jbms commented 6 months ago

Currently Neuroglancer does not rely on any third-party UI framework, and instead essentially has its own, with the following properties:

It appears that SolidJS is a promising alternative. SolidJS provides both a "reactive state management" library, which would replace the Signal/WatchableValue mechanism in Neuroglancer, and also a UI library built on top of that.

The SolidJS reactive state management library, which is very similar to MobX, avoids the need to manually register/unregister callbacks by instead tracking when the value contained in SolidJS's equivalent of Neuroglancer's WatchableValue (called a Signal in SolidJS) in order to infer dependencies automatically. Essentially it re-registers the necessary callbacks as one-time callbacks on each access, but does it a very efficient way.

The UI library is one the most efficient JavaScript UI libraries available. It allows UI "components" to be defined with JSX, similar to React, but avoids the overhead of a virtual DOM and instead relies on a compilation process via a babel plugin that directly generates the code for creating and updating the DOM nodes. It appears that the resultant code is likely fairly similar to what is currently done manually in Neuroglancer.

Migrating all of Neuroglancer at once would be impractical, but because the SolidJS model is quite similar to how Neuroglancer already works, I expect it should be possible to migrate individual components at a time. Neuroglancer WatchableValue objects can be mapped to SolidJS signals, and vice versa, and SolidJS UI components can similarly interoperate with Neuroglancer UI components in a straightforward way.

jbms commented 6 months ago

@chrisj Since you are doing a lot of work on Neuroglancer (both upstream and the Seung Lab fork) these days, I'd be interested in your thoughts about SolidJS.

chrisj commented 2 months ago

I didn't notice this until a couple months after you posted it. Finally got around to trying it out. Seems promising so far and the explicitness of the API seems like something dependable to build on. It would definitely be a strong candidate for a dependent project.