Skip to content

sparkline is very inefficient #48

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

Closed
bablokb opened this issue Apr 28, 2022 · 4 comments
Closed

sparkline is very inefficient #48

bablokb opened this issue Apr 28, 2022 · 4 comments

Comments

@bablokb
Copy link

bablokb commented Apr 28, 2022

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.

@FoamyGuy
Copy link

FoamyGuy commented Jul 2, 2022

We would welcome a PR with efficiency improvements

@bablokb
Copy link
Author

bablokb commented Jul 3, 2022

It is on my todo-list. Is backward-compatibility a must? If I change the code so that the x-values are not scaled to the full width, this will change the behavior.

@bablokb
Copy link
Author

bablokb commented Jul 5, 2022

Partly fixed by pr #50

@bablokb
Copy link
Author

bablokb commented Aug 15, 2022

closing the issue: fixed by merged commit #53

@bablokb bablokb closed this as completed Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants