Skip to content
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

Optimzation: code consolidation in drawCircle() #4302

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

DedeHai
Copy link
Collaborator

@DedeHai DedeHai commented Nov 22, 2024

  • replaced repeated function calls with loops
  • saves about 600bytes of flash
  • speed tradoff: drawing is now a tiny bit slower but insignificant in my tests

- saves about 600bytes of flash
- speed tradoff: drawing is now a tiny bit slower but insignificant in my tests
@WouterGritter
Copy link
Contributor

drawing is now a tiny bit slower but insignificant in my tests

What device have you tested it on? We need to make sure it doesn't pose an issue on the slowest supported devices.

@DedeHai
Copy link
Collaborator Author

DedeHai commented Nov 22, 2024

it won't pose any issue, as I mentioned, the slowdown is insignificant, tested on C3. The function is currently only used by ripple FX.

setPixelColorXY(cx-y, cy+x, col);
setPixelColorXY(cx+y, cy-x, col);
setPixelColorXY(cx-y, cy-x, col);
for (int i = 0; i < 4; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

My suggestion would be to compact the "soft" Wu's algo (as you did), but keep Bresenham's code untouched.
Why: in some cases speed does matter, so I'd like to have the basic circle drawing as fast as possible. Also you did not save much code on Bresenham.

The "soft" algorithm is much slower any way, so I'd agree with you that making the code more compact here is better for readability.

Copy link
Collaborator Author

@DedeHai DedeHai Nov 22, 2024

Choose a reason for hiding this comment

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

I ran a few more tests: there is no measureable difference in speed using the Bresenham's code, the "overhead" added by the loop is really small when comparing it to a setPixelColorXY() call. I got the exact same FPS with and without the changes using a modified ripple FX drawing about 100 circles. Also: there is no FX currently using the Bresenham's circle version.

With the Wu's algorithm, there is a slight drop in speed. Using the same modified ripple FX frame rate drops by 0.6FPS from 42FPS to 41.4FPS worst case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also: there is no FX currently using the Bresenham's circle version.

There's an open PR that uses it.

@softhack007 softhack007 added the optimization re-working an existing feature to be faster, or use less memory label Nov 22, 2024
@netmindz
Copy link
Collaborator

netmindz commented Dec 1, 2024

Now I've tagged 0.15.rc.1 - feel free to merge this @softhack007

@DedeHai
Copy link
Collaborator Author

DedeHai commented Dec 1, 2024

I would hold off with merging the optimization PRs to not accidentally introduce bugs. This PR serves one purpose only: code consolidation and flash optmization, it adds no features and fixes no issues.

@netmindz
Copy link
Collaborator

netmindz commented Dec 4, 2024

My plan for the GA release will be taken from the rc1 tag plus cherry pick of any fixes, not taking 0_15

@DedeHai
Copy link
Collaborator Author

DedeHai commented Dec 4, 2024

got it. I have quite a few PRs pending that need to go through beta testing. Shall I merge those into 0_15 or will there be a new branch?

@netmindz
Copy link
Collaborator

netmindz commented Dec 4, 2024

You are good to go ahead and merge into 0_15 as this will be merged into main and then deleted as soon as the 0.15.0 GA release happens

@netmindz netmindz changed the base branch from 0_15 to main December 16, 2024 13:24
@DedeHai DedeHai merged commit 83da756 into Aircoookie:main Dec 19, 2024
19 checks passed
@DedeHai DedeHai deleted the drawCircle_consolidate branch December 19, 2024 19:19
blazoncek pushed a commit to blazoncek/WLED that referenced this pull request Dec 25, 2024
- saves about 600bytes of flash
- speed tradoff: drawing is now a tiny bit slower but insignificant in my tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization re-working an existing feature to be faster, or use less memory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants