perf(consume): optimize multi-effect active effect application #126

Open
opened 2026-03-15 18:52:01 +00:00 by Athemis · 0 comments
Owner

Description

Optimize applyConsumeActiveEffects() for consumables with multiple active effects. The current implementation in src/apps/actor/consume-flow.js scans the target actor's effects, then processes every consume effect sequentially and awaits each duration roll inside the loop. That is acceptable for a single effect, but scales poorly for multi-effect consumables because replace lookups, toObject() cloning, flag merging, and duration evaluation all happen per entry in a strictly serialized path.

A follow-up should reduce the amount of sequential work in this path and keep the runtime cost closer to the actual number of changes that need to be persisted.

Context

Evidence:

  • src/apps/actor/consume-flow.js:94 builds existingKeys by scanning all target actor effects for every consume action.
  • src/apps/actor/consume-flow.js:107 iterates each consume effect entry.
  • src/apps/actor/consume-flow.js:127 to src/apps/actor/consume-flow.js:157 resolves and evaluates duration formulas with await durationRoll.evaluate() inside the loop.

This is the clearest remaining consume-flow hotspot after fixing eager description enrichment in #123.

### Description Optimize `applyConsumeActiveEffects()` for consumables with multiple active effects. The current implementation in `src/apps/actor/consume-flow.js` scans the target actor's effects, then processes every consume effect sequentially and awaits each duration roll inside the loop. That is acceptable for a single effect, but scales poorly for multi-effect consumables because replace lookups, `toObject()` cloning, flag merging, and duration evaluation all happen per entry in a strictly serialized path. A follow-up should reduce the amount of sequential work in this path and keep the runtime cost closer to the actual number of changes that need to be persisted. ### Context Evidence: - `src/apps/actor/consume-flow.js:94` builds `existingKeys` by scanning all target actor effects for every consume action. - `src/apps/actor/consume-flow.js:107` iterates each consume effect entry. - `src/apps/actor/consume-flow.js:127` to `src/apps/actor/consume-flow.js:157` resolves and evaluates duration formulas with `await durationRoll.evaluate()` inside the loop. This is the clearest remaining consume-flow hotspot after fixing eager description enrichment in #123.
Athemis self-assigned this 2026-03-15 20:18:15 +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
Athemis/ds4#126
No description provided.