Skip to content
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

Merged
merged 2 commits into from
Sep 28, 2024

Commits on Sep 22, 2024

  1. perf(store): avoid going over states list every time action is dispat…

    …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)
    ```
    arturovt committed Sep 22, 2024
    Configuration menu
    Copy the full SHA
    c1c8437 View commit details
    Browse the repository at this point in the history

Commits on Sep 28, 2024

  1. chore: update bundlemon

    arturovt committed Sep 28, 2024
    Configuration menu
    Copy the full SHA
    2bf876b View commit details
    Browse the repository at this point in the history