-
Notifications
You must be signed in to change notification settings - Fork 17
Description
I did some timings and discovered that sparkline is very inefficient. The cost of add_value is linear with the number of values added, not const. The reason is that add_value triggers a recreation of all primitives.
In my application I do data sampling at a rate of 10/s, but I update my display 1/s. But after every add_value all drawing primitives are recalculated. This problem could be solved by not calling update() from within add_value. An additional parameter update=True to add_value would solve this problem without breaking existing code.
But this is only part of the story.
I think in general you have two cases. In the first case you have all your data and want to calculate the sparkline. In this case it would be useful to have an add_values method that adds all data-points at once and then calculates the sparkline. The second case is on-the-fly plotting. Here it is not necessary to scale the x-axis to the full width. If a new data-point falls within the current scale (and width), no recreation of all primitives would be necessary, add_value would be an inexpensive operation. After the plot reaches the full width, a recalculation would be necessary though. This sort of optimization would not break existing code, but would change behavior.