Fix slow performance of polygon generation tool
Reusing the hitobjects now instead of removing them and regenerating everything from scratch each time. Also fixes the flashing whenever the polygon updates.
I put tryCreatePolygon() behind Scheduler.AddOnce for good measure, not sure if this is actually required as it's plenty fast either way now.
Before:
https://github.com/user-attachments/assets/fc2916ca-c742-4c84-be91-d46430c596bd
After:
https://github.com/user-attachments/assets/9cb73445-a3bb-4d54-a089-37e56c1ead08
How much of the "performance gain" here is the "reuse of objects"? I'd wager the .AddOnce() is doing the heavy lifting here if anything.
The majority of it comes from reusing the objects.
For comparison: (All the videos are recorded on release builds btw)
Index: osu.Game.Rulesets.Osu/Edit/PolygonGenerationPopover.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/osu.Game.Rulesets.Osu/Edit/PolygonGenerationPopover.cs b/osu.Game.Rulesets.Osu/Edit/PolygonGenerationPopover.cs
--- a/osu.Game.Rulesets.Osu/Edit/PolygonGenerationPopover.cs (revision 7e439be9eca9e626a080defc0cd24da933072710)
+++ b/osu.Game.Rulesets.Osu/Edit/PolygonGenerationPopover.cs (date 1728640773096)
@@ -125,7 +125,7 @@
tryCreatePolygon();
}
- private void scheduleRefresh() => Scheduler.AddOnce(tryCreatePolygon);
+ private void scheduleRefresh() => tryCreatePolygon();
private void tryCreatePolygon()
{
https://github.com/user-attachments/assets/467e06fa-bec3-4c68-8ad5-003b9c99f539
Ran it one more time with just Scheduler.AddOnce to double check, and it looks like it actually does have a noticeable effect, albeit much less than with just reusing the objects.
https://github.com/user-attachments/assets/fd417118-f96c-4f48-9edf-d4fd021d5da6