-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf(store): avoid going over states list every time action is dispatched #2219
base: master
Are you sure you want to change the base?
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 8a7cca6. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
commit: |
BundleMonFiles updated (1)
Unchanged files (5)
Total files change +1.07KB +0.84% Groups updated (2)
Final result: ❌ View report in BundleMon website ➡️ |
BundleMon (NGXS Plugins)Unchanged files (9)
No change in files bundle size Unchanged groups (1)
Final result: ✅ View report in BundleMon website ➡️ |
BundleMon (Integration Projects)Files updated (3)
Total files change +277B +0.13% Final result: ✅ View report in BundleMon website ➡️ |
dc59934
to
48afa41
Compare
…ched In this commit, I'm working on optimizing how we handle action dispatches by avoiding repeated traversal of the `states` list. Instead, we prepare a map each time a new state is added, allowing us to perform O(1) lookups by action type in the future. This approach reduces complexity and improves performance. I've tested it with benchmark.js, and here are the results: ``` class Increment { static readonly type = 'Increment'; } const states = Array.from({ length: 50 }).map((_, index) => { @State({ name: `counter_${index + 1}`, defaults: 0, }) @Injectable() class CounterState { @action(Increment) increment(ctx: StateContext<number>) { ctx.setState((counter) => counter + 1); } } return CounterState; }); store.dispatch() before changes x 3,435 ops/sec ±0.45% (65 runs sampled) store.dispatch() after changes x 3,942 ops/sec ±1.21% (25 runs sampled) ```
48afa41
to
8a7cca6
Compare
Code Climate has analyzed commit 8a7cca6 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 95.3% (0.0% change). View more on Code Climate. |
In this commit, I'm working on optimizing how we handle action dispatches by avoiding repeated traversal of the
states
list. Instead, we prepare a map each time a new state is added, allowing us to perform O(1) lookups by action type in the future. This approach reduces complexity and improves performance.I've tested it with benchmark.js, and here are the results: