Repository navigation
fix(signals): make getState linear in the number of state keys - #5232
Open
lskrajny-marcura wants to merge 1 commit into
Open
lskrajny-marcura wants to merge 1 commit into
lskrajny-marcura wants to merge 1 commit into
Conversation
Closes ngrx#5231 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 of 2 tasks
✅ Deploy Preview for ngrx-io ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
This branch has not been deployed
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.
PR Checklist
Please check if your PR fulfills the following requirements:
No new tests: the output of
getStateis unchanged, and the existinggetState/patchState/watchStatespecs (including the symbol-key state instate-source.spec.ts) cover it. A timing assertion would be flaky, so the benchmark is in the issue instead.PR Type
What kind of change does this PR introduce?
What is the current behavior?
getStatebuilds the state by spreading the accumulator once per key, so each call is O(n²) in the number of state keys.patchState,withReducerand state watchers call it on every state change. With 400 keys, 2000getStatecalls take ~7.5 s.Closes #5231
What is the new behavior?
getStatefills one object in a loop, so it is linear. The result is the same: a new plain object with the same own keys (string and symbol) in the same order. With 400 keys, 2000 calls take ~0.11 s. Full numbers are in #5231.Does this PR introduce a breaking change?
Other information
Signals specs pass locally (
vitest run --config modules/signals/vitest.config.mts: 889 tests). The only failing files were the migration/schematics specs that need adist/build first; this change does not touch them.🤖 Generated with Claude Code