perf: cut per-frame allocations and redundant work on hot paths#79
Merged
Conversation
Three hot-path cleanups, all behavior-preserving: - SpringResolver.get_all_bone_names() now returns a PackedStringArray cached at _init_bones() instead of rebuilding it from _bones.keys() on every call. The key set is fixed once the rig is built, and the getter is read every physics frame across ~12 call sites (controller, HUD, foot-IK). - ActiveRagdollController computes _compute_balance_state() once per stagger frame and passes it into _apply_active_resistance(), instead of each computing its own. It sums center-of-mass over every body; bodies don't move between the two reads (only spring strengths change), so the shared value is identical — was being computed twice per stagger frame. - StrengthDebugHUD calls set_process(false) while the overlay is off (it starts off) and re-enables it on F3 toggle, so it does no per-frame queue_redraw work until actually shown. Validated: headless import clean; GUT 112/112 (3x stable); scene-smoke clean on euphoria_showcase + demo. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three behavior-preserving hot-path cleanups for the 0.3.x finalization gate. No feel changes — these only remove redundant per-frame work.
1.
SpringResolver.get_all_bone_names()— cache the rig-name listThe getter rebuilt a
PackedStringArrayfrom_bones.keys()on every call, and it's read every physics frame across ~12 call sites (controller stagger/recovery/ragdoll loops, foot-IK, HUD). The bone key set is fixed once_init_bones()runs, so it's now cached there and the getter returns the cached array (callers already only iterate it read-only).2.
ActiveRagdollController— compute balance once per stagger frame_compute_balance_state()sums center-of-mass over every rig body. During stagger it was computed twice per frame — once inside_apply_active_resistance()and once in_update_stagger(). Bodies don't move between those two reads (only spring strengths change), so the result is identical; it's now computed once and passed in.3.
StrengthDebugHUD— disable_processwhile offThe overlay starts off and is toggled with F3, but
_processran every frame regardless. It nowset_process(false)at_ready()and toggles processing with the detail level, so there's zero per-frame cost until shown.Validation
--quit-after 150): clean oneuphoria_showcase(exercises the active-resistance/stagger path) anddemoVisual sign-off
Per the gate process, this wants a quick in-editor spot-check (stagger feel unchanged, F3 HUD still toggles correctly) before merge — though the changes are allocation/scheduling only and shouldn't alter feel.
🤖 Generated with Claude Code