Skip to content

Share per-frame state between GetHeight and Draw#74

Merged
VPDPersonal merged 1 commit into
feature/serialize-reference-dropdownfrom
perf/sr-imgui-drawer-per-frame-state
Jun 23, 2026
Merged

Share per-frame state between GetHeight and Draw#74
VPDPersonal merged 1 commit into
feature/serialize-reference-dropdownfrom
perf/sr-imgui-drawer-per-frame-state

Conversation

@VPDPersonal

Copy link
Copy Markdown
Owner

Summary

  • The [SerializeReference] IMGUI drawer asked HasSharedReference for every managed-reference field from both GetHeight and Draw on each repaint, and each call did a full SerializedObject walk — 2·N whole-object walks per frame. HasSharedReference now builds the object's managed-reference id → use-count once per (SerializedObject, frame) and reuses it, so the object is walked once per repaint instead of 2·N times.
  • SerializeReferenceRequiredGate.ResolveFieldInfo now memoises its reflection walk by (target type, property path) — like the existing RequiredFieldCache — so IsViolation / TryGetRequired (also called from both GetHeight and Draw) reflect each path once instead of re-walking it every frame.

Notes for review

  • The alias detection switched from "another field at a different path shares my id" to "my id is used by more than one field". These are equivalent: a field's own path contributes exactly 1 to its id's count, so count > 1 means at least one other field aliases it. The existing managedReferenceValue is null guard still short-circuits empty references first.
  • The per-frame alias cache is keyed by Time.frameCount + the SerializedObject reference; an in-frame mutation (e.g. MakeReferenceUnique) is applied via a button click that ends the draw and rebuilds the inspector next frame, so the cache rebuilds then — same staleness tolerance as the existing per-selection _mixedResult memo.
  • The ResolveFieldInfo cache is static and never explicitly cleared, which matches RequiredFieldCache in the same class: the reflected field set is stable until a domain reload wipes statics.

Linked issues

Refs #49 - addresses review finding #49 (comment)

@VPDPersonal VPDPersonal added type: performance Performance improvement status: needs-review Ready for review area: editor Editor-only code labels Jun 21, 2026
@VPDPersonal VPDPersonal merged commit 7762e07 into feature/serialize-reference-dropdown Jun 23, 2026
1 check passed
@VPDPersonal VPDPersonal deleted the perf/sr-imgui-drawer-per-frame-state branch June 23, 2026 14:04
@github-actions github-actions Bot removed the status: needs-review Ready for review label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: editor Editor-only code type: performance Performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant