forked from ladyada/Adafruit_CircuitPython_Display_Shapes
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 thatadd_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 callingupdate()
from withinadd_value
. An additional parameterupdate=True
toadd_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.The text was updated successfully, but these errors were encountered: