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

Avoid expensive sqrt operation in hot loop of BitMap.grow_mask #96885

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

LuizZak
Copy link
Contributor

@LuizZak LuizZak commented Sep 11, 2024

I've noticed that BitMap.grow_mask could be quite slow for large radii on large images, and while looking for ways to optimize the process I noticed that the operation performs a distance_to that could be converted into a distance_squared_to, avoiding a sqrt from being performed on every pixel, multiple times.

Guidance is requested on perhaps how to ensure this doesn't lead to an unwanted regression on pixels on the edge of expanded bitmaps.

@akien-mga akien-mga added this to the 4.x milestone Sep 12, 2024
@LuizZak
Copy link
Contributor Author

LuizZak commented Sep 12, 2024

I may have come up with a better solution involving an intermediary BitMap that holds pre-computed distances, but since this change is way simpler I'll opt to open a separate PR after this one gets closed.

Copy link
Member

@AThousandShips AThousandShips left a comment

Choose a reason for hiding this comment

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

LGTM

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Sep 13, 2024
@akien-mga akien-mga changed the title Avoid expensive sqrt operation in hot loop of BitMap.grow_mask Avoid expensive sqrt operation in hot loop of BitMap.grow_mask Sep 13, 2024
@akien-mga akien-mga merged commit f2ce94f into godotengine:master Sep 13, 2024
20 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

@LuizZak LuizZak deleted the grow_mask_sqrt_fix branch September 13, 2024 11:56
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.

4 participants