Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Limit the number of writes to improve performance #22

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

Merged
merged 3 commits into from
Nov 10, 2022

Conversation

grouma
Copy link
Contributor

@grouma grouma commented Nov 1, 2022

The current dispaly.show() command is very slow and takes roughly a second to complete. I discovered from this thread that it's likely due to the Linux scheduler limiting how fast one can send data to the SPI hardware. To overcome this issue we now do a single write command. This significantly improves the performance which makes for a nearly instant screen response.

This resolves #18

@tekktrik tekktrik requested a review from a team November 1, 2022 15:21
Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't test, but this all looks pretty reasonable to me. Just a few housekeeping changes.

@@ -135,7 +138,7 @@ def image(self, img):
self.buf[i] = 0
# Iterate through the pixels
for x in range(width): # yes this double loop is slow,
for y in range(height): # but these displays are small!
for y in range(height): # but these displays are small!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a manual? My guess this whitespace change is what's making black angry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatically formatted by VS Code. I'm not sure what black is in reference to. I can revert this change if you wish but it's probably good cleanup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's just that the CI will continue to complain. If you want to be extra sure, you can run pre-commit yourself, and let it decide what how to format everything. Pre-commit is what the CI uses, so that's the surest way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black is a formatter, and our CI tool pre-commit uses it to standardize the formatting of our code.

@grouma
Copy link
Contributor Author

grouma commented Nov 3, 2022

Didn't test, but this all looks pretty reasonable to me

I was able to run some experiments. Before this change I got about 1 fps on my Raspberry Pi Zero W. With this change I get about 14 fps. It's a lot better but still isn't great given the actual power of the board. It'd be great if there was an easy to install library that unlocked the whole performance of the display. Something like: https://github.com/wrobell/smemlcd

@tekktrik
Copy link
Member

tekktrik commented Nov 3, 2022

Always happy to look at PRs! And I think your changes fixed the original issue, but the CI is having it's own hiccups with the new move to Python 3.11. I'm going to leave this here for just a bit to see if we can quickly resolve that but I'm pretty sure there's nothing else on your end!

Copy link
Member

@tekktrik tekktrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@tekktrik tekktrik merged commit 47250da into adafruit:main Nov 10, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 11, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_CharLCD to 3.4.4 from 3.4.3:
  > Merge pull request adafruit/Adafruit_CircuitPython_CharLCD#73 from BiffoBear/add_typing
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_LIS3DH to 5.1.19 from 5.1.18:
  > Merge pull request adafruit/Adafruit_CircuitPython_LIS3DH#73 from crotwell/extra_underscore
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_SharpMemoryDisplay to 1.4.6 from 1.4.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_SharpMemoryDisplay#22 from grouma/main
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions

Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 6.0.0 from 5.5.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#125 from BiffoBear/Make_is_connected_return_bool
  > Update .pylintrc for v2.15.5
  > Fix release CI files
  > Update pylint to 2.15.5
  > Updated pylint version to 2.13.0
  > Switching to composite actions
@ilikecake
Copy link
Contributor

Oh Hey, I am glad someone made this change. I kept meaning to get back to this but life keeps getting in the way. :) if you are running on a Raspberry Pi and have not already tried it, add Numpy to your installation. I made another small change that speeds up the image function if Numpy is present. See here for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Performance issues with Raspberry Pi
3 participants