Skip to content

30% speedup of polybool by sorting events descending instead of ascending? #11

Description

@Fribur

This may or may not be an issues in Typescript: removing index [0] in an array will cause all the other elements to shift. This is currently the case for every removal of an event from the event queue:

return this.nodes[0];

In my C# port, I found a 30% speedup of polybool overall by sorting the events the other way around, and thereby making the last index the head. https://github.com/Fribur/TextMeshDOTS/blob/fd85270dfe76f80597b4225ac1750665a4f59f9a/Polybool/IComparer/EventQueueComparer.cs#L11. I found another 10% speedup by sorting events in one go after adding to list, and not for each item. https://github.com/Fribur/TextMeshDOTS/blob/fd85270dfe76f80597b4225ac1750665a4f59f9a/Polybool/Intersecter.cs#L59

Interestingly, despite those optimizations, and a couple of other optimizations (removing redundant expensive math in intersection test), Clipper 2 (is in same linked repository) is still 30% faster for a single pass over all segments in my tests and ~3x faster for 3 passes (segments1, segments2, combined)...so I might stick with it for the purpose of cleaning up self overlapping glyphs after all.

(Note: both Clipper and PolyBool have been made compatible with the Unity BURST compiler, which makes them ~100 faster compared to not using BURST compilation. The only caveat is that I cannot use classes, everything has to be structs...which comes at the cost of code readability and some indirection (e.g. storing segments outside of events in dedicated list).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions