perf(animator): cache the spring settle time - #226
Merged
Merged
Conversation
LeadcodeDev
force-pushed
the
fix/gradient-angle
branch
from
September 21, 2026 23:39
5e08139 to
8294064
Compare
LeadcodeDev
force-pushed
the
perf/spring-settle-cache
branch
from
September 21, 2026 23:39
1526e13 to
eda0946
Compare
53 tasks
LeadcodeDev
force-pushed
the
fix/gradient-angle
branch
from
September 22, 2026 06:09
4878d51 to
126c5df
Compare
LeadcodeDev
force-pushed
the
perf/spring-settle-cache
branch
from
September 22, 2026 06:09
dfa79d7 to
d5f4911
Compare
LeadcodeDev
force-pushed
the
fix/gradient-angle
branch
from
September 22, 2026 08:33
126c5df to
0aeadf7
Compare
LeadcodeDev
force-pushed
the
perf/spring-settle-cache
branch
from
September 22, 2026 08:33
d5f4911 to
4cbf315
Compare
LeadcodeDev
force-pushed
the
fix/gradient-angle
branch
from
September 22, 2026 08:43
0aeadf7 to
bb3f26f
Compare
LeadcodeDev
force-pushed
the
perf/spring-settle-cache
branch
from
September 22, 2026 08:43
4cbf315 to
3dc1213
Compare
LeadcodeDev
changed the base branch from
fix/gradient-angle
to
chantier/audit-2026-09
September 22, 2026 08:52
LeadcodeDev
force-pushed
the
perf/spring-settle-cache
branch
from
September 22, 2026 08:58
3dc1213 to
62bfbd0
Compare
`spring_value` is reached per animated property, per node, per frame (`box_builder.rs:538` -> `resolve_props_for_effects` -> `resolve_animation_value_full`, animator.rs:997). When `SpringConfig::duration` is set, each of those calls runs a full coarse scan plus 40 bisection steps, with `steps` clamped to [2000, 20000]. For the shipped defaults (stiffness 100, mass 1 -> omega 10, period 0.628 s) `desired_steps` is 2292, so one animated property costs ~2333 `exp`/`sin`/`cos` evaluations per frame to recompute a value that depends only on (damping, stiffness, mass, rest_threshold) — completely invariant across frames. A 30 s/60 fps render with 20 nodes carrying two spring-duration properties each burns roughly 165 million redundant solver evaluations. The function's own doc comment acknowledges it is "called on every `spring_value` sample when `duration` is set". Refs #220
LeadcodeDev
force-pushed
the
perf/spring-settle-cache
branch
from
September 22, 2026 09:04
62bfbd0 to
99a9496
Compare
LeadcodeDev
added a commit
that referenced
this pull request
Sep 22, 2026
`spring_value` is reached per animated property, per node, per frame (`box_builder.rs:538` -> `resolve_props_for_effects` -> `resolve_animation_value_full`, animator.rs:997). When `SpringConfig::duration` is set, each of those calls runs a full coarse scan plus 40 bisection steps, with `steps` clamped to [2000, 20000]. For the shipped defaults (stiffness 100, mass 1 -> omega 10, period 0.628 s) `desired_steps` is 2292, so one animated property costs ~2333 `exp`/`sin`/`cos` evaluations per frame to recompute a value that depends only on (damping, stiffness, mass, rest_threshold) — completely invariant across frames. A 30 s/60 fps render with 20 nodes carrying two spring-duration properties each burns roughly 165 million redundant solver evaluations. The function's own doc comment acknowledges it is "called on every `spring_value` sample when `duration` is set". Refs #220
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.
Severity Low, category quality. Location:
crates/rustmotion-core/src/engine/animator.rs:470Impact
spring_valueis reached per animated property, per node, per frame (box_builder.rs:538->resolve_props_for_effects->resolve_animation_value_full, animator.rs:997). WhenSpringConfig::durationis set, each of those calls runs a full coarse scan plus 40 bisection steps, withstepsclamped to [2000, 20000]. For the shipped defaults (stiffness 100, mass 1 -> omega 10, period 0.628 s)desired_stepsis 2292, so one animated property costs ~2333exp/sin/cosevaluations per frame to recompute a value that depends only on (damping, stiffness, mass, rest_threshold) — completely invariant across frames. A 30 s/60 fps render with 20 nodes carrying two spring-duration properties each burns roughly 165 million redundant solver evaluations. The function's own doc comment acknowledges it is "called on everyspring_valuesample whendurationis set".Fix
Memoize
spring_settle_timeon the quantized(damping, stiffness, mass, threshold)tuple in a thread-localHashMap, or precomputetime_scaleonce when theSpringConfigis resolved and carry it on the resolved animation instead of recomputing it insidespring_value.Evidence the audit read
Part of the September 2026 audit remediation chantier. Refs #220 (RM-37).