ChartJs.Blazor
ChartJs.Blazor copied to clipboard
Performance improvements
This issue is an unordered collection of some performance improvements we could/should consider. It doesn't have high priority and will change from time to time but if there's something important in this list, we can transfer it in its own issue with more details and audit a fix for it.
- Cache the converter-array used when deserializing the
ExpandoObject
inChartJsInterop.cs
https://github.com/mariusmuntean/ChartJs.Blazor/blob/bc4cb3bee81379dba1e0e3af7eeaa2c90317fdd8/src/ChartJs.Blazor/ChartJS/ChartJsInterop.cs#L122 - Refactor
IndexableOptionConverter
to stop or minimize using reflection. This probably also comes with an internal refactoring ofIndexableOption
. It should stay API-compatible but there might be something we can do with the generics. Also the equality stuff doesn't seem right but that's not a performance issue.
Another tremendous performance improvement would be moving to System.Text.Json. It's already included (and used) with the standard JSRuntime, it's very high-performance and, having two Json (de)serializers does take up a bit of unneeded space.
Absolutely right. Unfortunately we can't do that currently :/
I have invested quite a bit of time into it and you can go down a really deep rabbit hole with this and this issue if you're interested. Also see this comment block.
Also Chart.js 3.0 is almost done and I think as soon as that's here, a lot needs to be done in this repo as well. Although I admittedly have my doubts, I hope we can finish version 2.0 of ChartJs.Blazor before Chart.js V3 is released. As mentioned on almost all of my comments by now, I simply don't have the time to work on this library at the moment and I hope that'll change in the future.
Shame, but I see it isn't as plug & play as the docs make it seem. I'd love to help with finishing ChartJs.Blazor, but I don't think you want my help. I literally just finished my first Blazor project, so I can only wish you the best of luck with the project.
No it's definitely not plug and play at least not with the way we use json.net. There's a lot of json.net features that System.Text.Json doesn't have because they were deemed unnecessary and or to improve performance.
Don't say we don't want your help, we always appreciate contributions :)
Also, you mention that you don't have a lot of experience with blazor, that's not an issue at all. 90% of this library is correctly serializing the chart configuration and figuring out ways to use it to allow for all the features while being completely typesafe. That's of course a challange since Chart.js is written in and for JavaScript. There are parts that are related to the interop and there you need some knowledge about blazor, JavaScript and it's interop.
Feel free to take on an issue and submit a pull request. I can't promise that we'll be able to use your work but when I get time, I can definitely take a look at your PR. For example you could try to fix #133 by removing all the dataset collection stuff and replacing it with IList<IDataset>
and List<IDataset>
respectively. Also good summaries/comments are a thing I like to pay attention to.
Hmm, I suddenly feel motivated to help :). I might take a look (once school gets less busy :P).