-
-
Notifications
You must be signed in to change notification settings - Fork 112
PlotlyEditor handleUpdate mutates inputs instead of following unidirectional data flow #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Your point is well-taken, and we do share your enthusiasm for the React/unidirectional dataflow pattern! That said, the architecture of plotly.js was laid down before the current vogue for immutable data structures, and so it's taking us some time to evolve things towards a state where this kind of thing is possible. The recent advent of the I should note that it may not always be possible or desirable to make copies of everything, as some arrays in |
@nicolaskruchten You're not going to have to "copy a million entries" if all you're doing is appending, even in an arbitrarily-large example like that. Immutability just means calling |
I'm definitely not dismissing immutability, I'm working hard to promote it and we're making changes to plotly.js to use it! :) That said, copying large arrays is much slower than "not exactly the same" ... Per https://jsperf.com/copy-large-array/1 for me the slice-and-push operation runs at ~60 ops/sec and the push-only runs at ~30,000,000 ops/sec. |
@nicolaskruchten But that's just one part of the whole system necessary to actually fetch, render, and process user interaction events when dealing with data sets, even large ones. Your performance test ignores:
Is there an actual real-world scenario where the time difference between immutable vs mutations actually makes an impact compared to all the much slower and more visibly-slow timing of fetching data and the render loop? The only scenario I can think of where there's going to be many operations that quickly on a large ("millions") array of data is fetching real-time data via sockets. In which case, the network request turnaround and the render loop are both going to be much slower than any array manipulation code. Performance tests and time-based optimisations are great, but prematurely optimising without taking the entire system into consideration will cause more problems than the optimisation solves. |
I agree with everything you're saying, and with the changes we're making to plotly.js you will be able to build applications which use immutability to do shallow equality checks and so on. I'm also saying that we'll leave a mutability/revision-number escape hatch in case there are others who want to do things differently :) |
Once #384 settles down, it will be easier to resolve this (and #212, which was already intended to do this!) as per #384 (comment) |
Due to the way the editor is wired to depend on the
graphDiv
DOM element fromreact-plotly.js
,handleUpdate
is mutating thedata
/layout
, and then usesonUpdate
as a "something changed" flag. So, it's essentially just bypassing the React render loop altogether by flowing some data mutations directly back to the embedded Plotly insidereact-plotly.js
.What it should be doing is using something like
immutability-helper
to create an updated immutable copy ofdata
/layout
, and then send back those changes out as values to theonUpdate
callback. The callback would then update the higher state, and those new changes would flow back down into thedata
&layout
props of both thePlot
andPlotlyEditor
components.The text was updated successfully, but these errors were encountered: