Skip to content

perf: replace arrays with Maps in AnimationInputs for O(1) lookups#413

Merged
stormmuller merged 2 commits intotests-animation-inputsfrom
copilot/replace-inputs-with-maps
Jan 1, 2026
Merged

perf: replace arrays with Maps in AnimationInputs for O(1) lookups#413
stormmuller merged 2 commits intotests-animation-inputsfrom
copilot/replace-inputs-with-maps

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 1, 2026

Replaced array-based storage with Map-based storage in AnimationInputs to eliminate O(n) lookups. The class used arrays with .find() for retrieving inputs by name, which degrades as input count grows.

Changes

  • Changed textInputs, numberInputs, toggleInputs, triggerInputs from AnimationInput<T>[] to Map<string, AnimationInput<T>>
  • Updated _registerInput: array.some()map.has(), array.push()map.set()
  • Updated _getInput: array.find()map.get()
  • Updated update: iterate via triggerInputs.values() instead of direct array iteration

Impact

Public API unchanged. All lookups now O(1) instead of O(n).

// Before: O(n) scan through array
private _getInput<T>(name: string, animationInputArray: AnimationInput<T>[]) {
  return animationInputArray.find((input) => input.name === name) ?? null;
}

// After: O(1) map lookup
private _getInput<T>(name: string, animationInputMap: Map<string, AnimationInput<T>>) {
  return animationInputMap.get(name) ?? null;
}
Original prompt

Work on TODO: Performance - Replace textInputs, numberInputs, toggleInputs, and triggerInputs with maps (from src/animations/types/AnimationInputs.ts)

Created from VS Code via the GitHub Pull Request extension.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: stormmuller <17644200+stormmuller@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace textInputs, numberInputs, and toggleInputs with maps perf: replace arrays with Maps in AnimationInputs for O(1) lookups Jan 1, 2026
Copilot AI requested a review from stormmuller January 1, 2026 18:03
@stormmuller stormmuller marked this pull request as ready for review January 1, 2026 18:05
@stormmuller stormmuller merged commit f36d3de into tests-animation-inputs Jan 1, 2026
@stormmuller stormmuller deleted the copilot/replace-inputs-with-maps branch January 1, 2026 18:07
stormmuller added a commit that referenced this pull request Jan 1, 2026
* refactor: consolidate TODO comments for AnimationInputs tests

* refactor: update TODO comments for performance optimization in AnimationInputs

* refactor: remove redundant warning when adding existing systems and update TODO for system identification

* perf: replace arrays with Maps in AnimationInputs for O(1) lookups (#413)

* Initial plan

* perf: replace arrays with Maps in AnimationInputs for O(1) lookups

Co-authored-by: stormmuller <17644200+stormmuller@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stormmuller <17644200+stormmuller@users.noreply.github.com>

* Add tests for trigger inputs and default values in AnimationInputs (#412)

* Initial plan

* test: add comprehensive tests for trigger inputs and default values

Co-authored-by: stormmuller <17644200+stormmuller@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stormmuller <17644200+stormmuller@users.noreply.github.com>

* feat: use System instances as map keys for reliable system tracking (#414)

* Initial plan

* feat: add unique ID to System class using symbol-based pattern

Co-authored-by: stormmuller <17644200+stormmuller@users.noreply.github.com>

* refactor: add SystemCtor type for better type safety

Co-authored-by: stormmuller <17644200+stormmuller@users.noreply.github.com>

* refactor: use System instances as map keys instead of symbol IDs

Co-authored-by: stormmuller <17644200+stormmuller@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stormmuller <17644200+stormmuller@users.noreply.github.com>

* refactor: remove unused material classes and update exports in materials index

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: stormmuller <17644200+stormmuller@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants