8000 Optimizations by jepler · Pull Request #103 · adafruit/Adafruit_CircuitPython_LED_Animation · GitHub
[go: up one dir, main page]

Skip to content

Optimizations #103

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 2 commits into from
Nov 12, 2022
Merged

Optimizations #103

merged 2 commits into from
Nov 12, 2022

Conversation

jepler
Copy link
Contributor
@jepler jepler commented Nov 10, 2022

This improves the speed of the comet and chase (marquee) animations by eliminating expensive operations

In a test this improved speed substantially, nearly doubling
the speed of the following test program
```python
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=1, auto_write=False, pixel_order="RGB")
evens = helper.PixelMap(pixels, [(i,) for i in range(0, pixel_num, 2)], individual_pixels=True)
animation = RainbowChase(evens, 0, spacing=8)
t0 = adafruit_ticks.ticks_ms()
while True:
    for i in range(10):
        animation.animate(show=False)
    t1 = adafruit_ticks.ticks_ms()
    print(f"{10000/(t1-t0):.0f}fps")
    t0 = t1
```

Performance on Raspberry Pi Pico W:
Before: ~85fps
After: ~140fps

This also happens to make it compatible with an in-process PR that adds
a fast PixelMap-like class to the core, but which doesn't support
getitem.
The big pay-off is avoiding enumerate(). Removing redundant
comparisons of _ring() and avoiding modulo operations help too.
Copy link
Contributor
@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

This looks good to me. Thanks for the improvement @jepler.

I tested successfully on a Fun House with neopixel strip (30) with both comet and chase animations. Over 10,000 frames of the chase animation at speed 0.02 it was able to render all the frames about .3 seconds faster (~2.6s current to ~2.3s this branch). Improvements vary by animation type and configuration but have seen some speed increase on all permutations that I tried.

@tekktrik tekktrik merged commit 563f608 into main Nov 12, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Nov 13, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation to 2.6.1 from 2.6.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#103 from adafruit/optimizations
  > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#102 from tekktrik/dev/fix-pylint-errors
  > 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_Requests to 1.12.10 from 1.12.9:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#115 from DJDevon3/main
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#119 from tekktrik/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
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

Successfully merging this pull request may close these issues.

3 participants
0