From 3b44a0b44f21d50a7d2c7204a34cb438cea64f4b Mon Sep 17 00:00:00 2001 From: bd_ Date: Wed, 21 Aug 2024 19:23:36 -0700 Subject: [PATCH] perf: improve ScaleAdjusterPreview performance (#1026) --- Editor/ScaleAdjuster/ScaleAdjusterPreview.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs b/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs index 7b36998c..49d75a8b 100644 --- a/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs +++ b/Editor/ScaleAdjuster/ScaleAdjusterPreview.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; -using nadena.dev.modular_avatar.core.editor.plugin; using nadena.dev.modular_avatar.core.editor.ScaleAdjuster; using nadena.dev.ndmf.preview; using UnityEditor; @@ -125,7 +124,18 @@ namespace nadena.dev.modular_avatar.core.editor } } - _boneArray = context.Observe(smr, s => s.bones, Enumerable.SequenceEqual); + _boneArray = context.Observe(smr, s => s.bones, (b1, b2) => + { + // SequenceEqual is quite slow due to having to go through Unity native calls for each object, use + // reference equality instead + if (b1.Length != b2.Length) return false; + + for (var i = 0; i < b1.Length; i++) + if (!ReferenceEquals(b1[i], b2[i])) + return false; + + return true; + }); _newBoneArray = new Transform[_boneArray.Length]; }