Hey guys, was going to raise a github feature request for this but wanted to ask about this in advance and if its even feasible for the project. A couple of weeks ago while on a personal project with plotly-js I came across apache arrow js and how if that we was used, the json serialisation cost and the deserialisation cost are almost instant ie closer to 3ms, and then it doesnt need to decode the data. Even with compared against the orjson version we have.
So in my limited implementation I saw upto 2seconds improvements for larger graphs. I could contribute to the project on github for this feature request but just wanted to ask in advance before I raise it there and here.
Hi @nilzagdev and welcome to the Dash community.
A 2 second improvement is great. Can you say more about your project? Can you share an example that reproduces the performance improvement?
Did it require changes just in Plotly js, or did the dash Graph component need to change as well?
Heya,
The project is similar to what I do at what work where we use plotly.js, plotly python and dash (de as well).
It just maintly about showing future forecasts so stacked line graphs, I need to send a lot of data to render it, and what I did notice was that most of the time was spent spend on serialisation and deserialisation of the data. At work we use Dash, in my personal project I used plotly.js and arrow to serialise and decode the data.
I can share the example over the weekend if thats alrgiht?
On the plotly.js side it wasn’t that complicated at all, instead of json->arrow to plotly . Instead of that I used tablefromIPC and Tabletoarray from arrow. It required no actual change on plotly.js.
I am pretty sure I can replicate this over the Dash Python Code as well, it would need to be an optional thing as this would only work with graphs which would be passed in data via arrow format, so only newer pandas, pyarrow or polars
Yes, sharing an example later is good - I’m interested to take a look!
Nevermind! I processed your note about Dash/Python after I wrote this. I think that would be high value!
My original comment: Not to blow up the scope of this idea, but if we introduce a more efficient data format for the data client-side we should also consider whether it could be leveraged directly for the Plotly.py → Plotly.js wire format since that’s the other place serialization-deserialization is currently quite expensive. We saw notable performance improvements when we compressed the data using base64, so I imagine there are more gains possible there!
in the GUI for the bumps scientific fitting package, we convert the plotly figures to dict with fig.to_dict() then send them over the wire using msgpack instead of JSON , just for speed as described above. We then show them in our web interface with the plotly.js Plotly.react function. msgpack is nice because it doesn’t need a schema
Hey @nilzagdev thanks for the suggestion here. We have some work in progress in this PR: Serialize only the values the JSON encoder cannot take by T4rk1n · Pull Request #4067 · plotly/dash · GitHub that will speed up the serialization by using msgspec (if installed). This might address the same performance concern you’re raising here. We could also consider adding arrow support as part of that effort. Have a look and let us know if you think it will help address your concern here!
Cheers,
Adrian
Worth separating the two costs: msgspec can cut server-side encoding while the browser still has to parse and materialize the JSON; Arrow mainly helps transfer and client-side decode of large numeric columns. For stacked line traces, the Arrow path would still need to map columns into x/y arrays, so a benchmark reporting encode time, payload size, browser parse/decode time and draw time separately would show whether it is additive to the msgspec PR. Keeping it optional with the existing JSON path as fallback seems sensible.