[Performance] Animation property dispatch resolves property name by strcmp cascade every frame #342

Closed
opened 2026-07-10 21:57:19 +00:00 by john · 0 comments
Owner

Problem

Every active animation applies its value every frame via Animation::applyValuetarget->setProperty(targetProperty, val) (src/Animation.cpp:438, called from Animation::update at src/Animation.cpp:264).

UIFrame::setProperty(const std::string& name, float value) (src/UIFrame.cpp:843) — and the parallel implementations on the other drawables/entities — resolve the property name with a linear if (name == "x") … else if (name == "y") … string-comparison cascade. Deep properties (e.g. fill_color.a) sit at the end of the chain, ~15 comparisons deep, and this runs per animation, per frame.

Cost scales with (animations × framerate): a scene animating 50 entities pays this ~3000×/sec.

Proposed fix

Resolve the property name once at Animation::start() / startEntity() — to a property enum or a cached setter (function pointer / small dispatch handle) — and reuse it each frame instead of re-parsing the string. This mirrors the approach in #331 (stop repeating per-call ceremony in the hot path).

Benchmark

Benchmarkable A/B exactly like #331: animate N properties across N frames headless, measure ns/frame before and after. Add to tests/benchmarks/.

Related: #331 (hot property getter fast-path).

## Problem Every active animation applies its value every frame via `Animation::applyValue` → `target->setProperty(targetProperty, val)` (`src/Animation.cpp:438`, called from `Animation::update` at `src/Animation.cpp:264`). `UIFrame::setProperty(const std::string& name, float value)` (`src/UIFrame.cpp:843`) — and the parallel implementations on the other drawables/entities — resolve the property name with a linear `if (name == "x") … else if (name == "y") …` **string-comparison cascade**. Deep properties (e.g. `fill_color.a`) sit at the end of the chain, ~15 comparisons deep, and this runs **per animation, per frame**. Cost scales with (animations × framerate): a scene animating 50 entities pays this ~3000×/sec. ## Proposed fix Resolve the property name **once** at `Animation::start()` / `startEntity()` — to a property enum or a cached setter (function pointer / small dispatch handle) — and reuse it each frame instead of re-parsing the string. This mirrors the approach in #331 (stop repeating per-call ceremony in the hot path). ## Benchmark Benchmarkable A/B exactly like #331: animate N properties across N frames headless, measure ns/frame before and after. Add to `tests/benchmarks/`. Related: #331 (hot property getter fast-path).
john closed this issue 2026-07-11 03:02:54 +00:00
Sign in to join this conversation.
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
john/McRogueFace#342
No description provided.