3 ms·
With the right abstractions and (adhered-to) guidelines, a library in a non-preemptive language can allow your code to effectively yield to the scheduler so oft
by btown 10y ago
With the right abstractions and (adhered-to) guidelines, a library in a non-preemptive language can allow your code to effectively yield to the scheduler so often that you get many of the benefits of preemptiveness. React is moving in this direction with their ongoing Fiber project [0] - since components are encouraged to be granular, and must be loosely coupled, the new React scheduler can take well-structured React code and plan the rendering of various subtrees with high levels of control. In fact, there's a TON of similarities between React's component model and the BEAM actor model: a component's "mailbox" consists of inbound props, outbound async callbacks to the component that requested its instantiation, and outbound assertions that the component desires to communicate props to new instances of other components.
One could imagine a compiler that inserts a yield around the calculation done in each Elixir AST node, and/or one which allows first-class representation of React components as Elixir processes, complete with JSX-like syntax. Very interesting to think about.
[0] https://github.com/acdlite/react-fiber-architecture https://github.com/acdlite/react-fiber-architecture
EDIT: Should also add that the shared-nothing messaging model translates very well to the requirements for Web Worker interop, so you actually could get multithreading.
- felixgallo 10y agothere's essentially no similarity at all between React's component model and the BEAM actor model, except that there's handlers. React and JS have no notion of backpressure, work-stealing schedulers, NUMA, per-actor GC, the list goes on forever.
- btown 10y agoAll true and duly noted, though readers may be interested in how sophisticated Fiber's scheduler may end up being: https://github.com/facebook/react/blob/39278c41e2f98d357f166a5523e3194fc5242d9d/src/renderers/shared/fiber/ReactFiberScheduler.js#L634 https://github.com/facebook/react/blob/39278c41e2f98d357f166...