ngxs / store

🚀 NGXS - State Management for Angular
http://ngxs.io
MIT License
3.54k stars 405 forks source link

perf(store): prevent initializing state factory at feature levels #2262

Closed arturovt closed 6 days ago

arturovt commented 1 week ago

In this commit, we mark the state factory as a root provider to prevent its initialization at feature levels when provideStates is called.

Previously, the state factory was initialized at feature levels because it needed to retrieve the feature-level injector in order to call injector.get(FeatureStateClass). This was necessary because, when NgxsModule.forFeature([BlogState]) was called, the BlogState instance could only be retrieved from the feature injector hierarchy.

Now, since addAndReturnDefaults is called at the feature level inside the feature environment initializer, it is executed within the feature injection context, allowing us to use the inject(...) function directly.

nx-cloud[bot] commented 1 week ago

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 456efc0c3fc84f3858bab08062a84dfa5e5173a4. 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 targets - [`nx run-many --target=test --all --configuration=ci --maxWorkers=4`](https://cloud.nx.app/runs/JF0CzS0xCK?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=lint --all --exclude=create-app`](https://cloud.nx.app/runs/xC9DcFXKjw?utm_source=pull-request&utm_medium=comment) - [`nx lint-types store`](https://cloud.nx.app/runs/ZV5Gp131kb?utm_source=pull-request&utm_medium=comment) - [`nx run-many --target=build --all`](https://cloud.nx.app/runs/ZLBXFwqgD9?utm_source=pull-request&utm_medium=comment)

Sent with 💌 from NxCloud.

pkg-pr-new[bot] commented 1 week ago

Open in Stackblitz

@ngxs/devtools-plugin

``` yarn add https://pkg.pr.new/@ngxs/devtools-plugin@2262.tgz ```

@ngxs/form-plugin

``` yarn add https://pkg.pr.new/@ngxs/form-plugin@2262.tgz ```

@ngxs/hmr-plugin

``` yarn add https://pkg.pr.new/@ngxs/hmr-plugin@2262.tgz ```

@ngxs/router-plugin

``` yarn add https://pkg.pr.new/@ngxs/router-plugin@2262.tgz ```

@ngxs/storage-plugin

``` yarn add https://pkg.pr.new/@ngxs/storage-plugin@2262.tgz ```

@ngxs/store

``` yarn add https://pkg.pr.new/@ngxs/store@2262.tgz ```

@ngxs/websocket-plugin

``` yarn add https://pkg.pr.new/@ngxs/websocket-plugin@2262.tgz ```

commit: 456efc0

bundlemon[bot] commented 1 week ago

BundleMon

Files updated (1) Status | Path | Size | Limits :------------: | ------------ | :------------: | :------------: :white_check_mark: | fesm2022/ngxs-store.mjs
| 100.1KB (-1.04KB -1.03%) | 103KB / +0.5%
Unchanged files (5) Status | Path | Size | Limits :------------: | ------------ | :------------: | :------------: :white_check_mark: | fesm2022/ngxs-store-internals.mjs
| 11.29KB | 13KB / +0.5% :white_check_mark: | fesm2022/ngxs-store-internals-testing.mjs
| 6.83KB | 7KB / +0.5% :white_check_mark: | fesm2022/ngxs-store-operators.mjs
| 6.22KB | 7KB / +0.5% :white_check_mark: | fesm2022/ngxs-store-plugins.mjs
| 2.38KB | 3KB / +0.5% :white_check_mark: | fesm2022/ngxs-store-experimental.mjs
| 1.4KB | 2KB / +0.5%

Total files change -1.04KB -0.8%

Groups updated (2) Status | Path | Size | Limits :------------: | ------------ | :------------: | :------------: :white_check_mark: | @ngxs/store(fesm2022)[gzip]
./fesm2022/*.mjs
| 30.8KB (-202B -0.64%) | +1% :white_check_mark: | @ngxs/store(esm2022)[gzip]
./esm2022/**/*.mjs
| 223.43KB (-947B -0.41%) | +1%

Final result: :white_check_mark:

View report in BundleMon website ➡️


Current branch size history | Target branch size history

bundlemon[bot] commented 1 week ago

BundleMon (NGXS Plugins)

Unchanged files (9) Status | Path | Size | Limits :------------: | ------------ | :------------: | :------------: :white_check_mark: | Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin.m
js
| 4.04KB | +0.5% :white_check_mark: | Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin.mjs
| 3.01KB | +0.5% :white_check_mark: | Plugins(fesm2022)[gzip]
hmr-plugin/fesm2022/ngxs-hmr-plugin.mjs
| 2.61KB | +0.5% :white_check_mark: | Plugins(fesm2022)[gzip]
websocket-plugin/fesm2022/ngxs-websocket-plug
in.mjs
| 2.57KB | +0.5% :white_check_mark: | Plugins(fesm2022)[gzip]
form-plugin/fesm2022/ngxs-form-plugin.mjs
| 2.45KB | +0.5% :white_check_mark: | Plugins(fesm2022)[gzip]
devtools-plugin/fesm2022/ngxs-devtools-plugin
.mjs
| 2.14KB | +0.5% :white_check_mark: | Plugins(fesm2022)[gzip]
logger-plugin/fesm2022/ngxs-logger-plugin.mjs
| 2.01KB | +0.5% :white_check_mark: | Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin-i
nternals.mjs
| 861B | +0.5% :white_check_mark: | Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin-int
ernals.mjs
| 396B | +0.5%

No change in files bundle size

Unchanged groups (1) Status | Path | Size | Limits :------------: | ------------ | :------------: | :------------: :white_check_mark: | All Plugins(fesm2022)[gzip]
./*-plugin/fesm2022/*.mjs
| 20.06KB | +0.5%

Final result: :white_check_mark:

View report in BundleMon website ➡️


Current branch size history | Target branch size history

bundlemon[bot] commented 1 week ago

BundleMon (Integration Projects)

Files updated (3) Status | Path | Size | Limits :------------: | ------------ | :------------: | :------------: :white_check_mark: | Main bundles(Gzip)
hello-world-ng17/dist-integration/main.(hash)
.js
| 68.13KB (-78B -0.11%) | +1% :white_check_mark: | Main bundles(Gzip)
hello-world-ng16/dist-integration/main.(hash)
.js
| 67.21KB (-79B -0.11%) | +1% :white_check_mark: | Main bundles(Gzip)
hello-world-ng18/dist-integration/browser/mai
n-(hash).js
| 69.98KB (-107B -0.15%) | +1%

Total files change -264B -0.13%

Final result: :white_check_mark:

View report in BundleMon website ➡️


Current branch size history | Target branch size history

codeclimate[bot] commented 1 week ago

Code Climate has analyzed commit 456efc0c 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.