perf: cache hot-path lookups + throttle LegCorrector raycasts #32

Merged
lavarius merged 1 commit from fix/perf-issues into master 2026-03-12 03:26:01 +00:00
Collaborator

Fixes #10, #11, #12, #13

Changes

#10 — CharacterStore GetComponent<Animator> in LateUpdate

  • Added Dictionary<GameObject, Animator> _animatorByModel populated once in Awake()
  • Cached LayerMask.NameToLayer("Character") as _characterLayer
  • LateUpdate and SwapModel now use the dictionary — zero GetComponent calls at runtime

#11 — AddCameraToStack MainCameraInstance.Instance every frame

  • Renamed field to _mainCameraInstance (was leaking as [SerializeField])
  • Cached in Start(), LateUpdate only retries while null

#12 — MovementManager Camera.main in LateUpdate

  • Removed the LateUpdate entirely — Start() already handles the null-safe cache

#13 — LegCorrector 6 raycasts/frame

  • Vector3[] arrays for foot points cached as class fields (no per-frame allocation)
  • Raycasts throttled to every raycastFrameInterval frames (default 3, tunable in Inspector)
  • Smoothing still runs every frame so animation stays fluid
Fixes #10, #11, #12, #13 ## Changes **#10 — CharacterStore `GetComponent<Animator>` in LateUpdate** - Added `Dictionary<GameObject, Animator> _animatorByModel` populated once in `Awake()` - Cached `LayerMask.NameToLayer("Character")` as `_characterLayer` - `LateUpdate` and `SwapModel` now use the dictionary — zero `GetComponent` calls at runtime **#11 — AddCameraToStack `MainCameraInstance.Instance` every frame** - Renamed field to `_mainCameraInstance` (was leaking as `[SerializeField]`) - Cached in `Start()`, LateUpdate only retries while null **#12 — MovementManager `Camera.main` in LateUpdate** - Removed the LateUpdate entirely — `Start()` already handles the null-safe cache **#13 — LegCorrector 6 raycasts/frame** - `Vector3[]` arrays for foot points cached as class fields (no per-frame allocation) - Raycasts throttled to every `raycastFrameInterval` frames (default 3, tunable in Inspector) - Smoothing still runs every frame so animation stays fluid
#10 CharacterStore: cache LayerMask.NameToLayer("Character") in Awake
  and use a Dictionary<GameObject,Animator> so LateUpdate and SwapModel
  never call GetComponent<Animator> at runtime.

#11 AddCameraToStack: cache MainCameraInstance in Start(); LateUpdate
  only retries while null — stops calling Instance getter every frame.

#12 MovementManager: removed redundant Camera.main call from LateUpdate;
  Start() already caches it. LateUpdate no longer exists for this class.

#13 LegCorrector: throttle 6 raycasts to every N frames (default 3,
  configurable via raycastFrameInterval). Cache Vector3[] arrays as
  class fields to eliminate per-frame heap allocations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
lavarius merged commit 0767f5844a into master 2026-03-12 03:26:01 +00:00
lavarius deleted branch fix/perf-issues 2026-03-12 03:26:01 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lavarius/ProjectOverlay!32
No description provided.