AprilRobotics / apriltag

AprilTag is a visual fiducial system popular for robotics research.
https://april.eecs.umich.edu/software/apriltag
Other
1.47k stars 522 forks source link

Optimize unionfind #294

Closed bouk closed 8 months ago

bouk commented 8 months ago

I figured out that a big part of the union find time spent was initializing the data array. I've optimized it by using two memsets instead of an array, which saves ~4% for an image sized 4896×3264

Before

Screenshot 2023-10-26 at 13 42 26

After

Screenshot 2023-10-26 at 13 42 13
christian-rauch commented 8 months ago

Is this essentially saving you 5ms on the 4896×3264 image? That's a nice improvement.

Could you explain in the commit message a bit what the change is doing and why it improves the performance? Glancing over this, Isee it's moving the parent and size from the struct ufrec into the struct unionfind, turning them into a point for arrays and then initialising all elements in the list at once instead of looping over the array of struct ufrec?

bouk commented 8 months ago

Expanded the commit message a bit. The savings is indeed from using memset instead of a for loop

christian-rauch commented 8 months ago

Can you remove the concrete ~4% from the commit message again? I guess this value depends a lot on the image resolution and is not the same improvement in all cases.

bouk commented 8 months ago

Sure, removed

christian-rauch commented 8 months ago

Thanks!