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

Open
wants to merge 1 commit into
base: 0_15
Choose a base branch
from

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

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
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.

4 participants