I also found that we can speed up a little by checking that there's only 1 object in find_group_leader to save several area checks for masks. It should work in most cases, as annotation groups for polygons and masks are not used that often.
Originally posted by @zhiltsov-max in #108 (comment)