NgRx Store vs. StoreDevtools: Evaluating Runtime‑Check Disabling for Low‑Traffic Apps
0 reputation · 28 Jun 2021, 06:59 UTC
0 reputation · 28 Jun 2021, 06:59 UTC
When a production Angular application has a very small state and receives minimal traffic, developers often consider turning off NgRx runtime checks (e.g., runtimeChecks: false in StoreModule.forRoot) to reduce bundle size and memory overhead. However, the NgRx DevTools extension remains bundled unless explicitly omitted, and it still relies on change‑detection hooks that can inflate memory usage even when runtime checks are disabled.
The core question is whether the small performance gains from disabling runtime checks justify the continued inclusion of DevTools in such a low‑traffic environment, or if the DevTools module should be removed altogether to maximize efficiency.
Key uncertainties include the exact memory footprint of DevTools when runtime checks are off, the impact on startup latency, and the trade‑off between debugging convenience and resource consumption.
Questions:
For a low-traffic Angular application with a small state tree, disabling runtimeChecks in production removes per-action CPU overhead, but it does not address the larger resource cost: StoreDevtools. If your priority is efficiency, exclude StoreDevtoolsModule from production builds entirely rather than relying on runtimeChecks: false alone. The runtime checks are development-time immutability guards; turning them off in production removes a safety net but saves only bounded work per dispatch. StoreDevtools adds bundle weight and maintains an in-memory action/state history that grows with usage, plus a communication bridge to the browser extension.
Confirmed: runtimeChecks and StoreDevtools are independent concerns. You can disable runtime checks while still shipping DevTools, or omit DevTools while keeping checks in staging. This assumes NgRx v8 or later, where both are configured separately in StoreModule.forRoot.
Likely: the memory and startup cost of StoreDevtools usually dominates the cost of runtime checks. Runtime checks add a small, bounded amount of work per action; DevTools adds a history buffer whose size scales with the number of actions and the size of each state snapshot. In a low-traffic app the absolute numbers are small, but the ratio still favors removing DevTools if you do not need production debugging. Because exact heap and latency numbers vary by application shape and NgRx version, treat the relative cost as a hypothesis to verify rather than a fixed measurement.
runtimeChecks: false in production, but keep them enabled in staging so mutation bugs surface before release.imports: [
StoreModule.forRoot(reducers, {
runtimeChecks: false,
}),
...(environment.production ? [] : [StoreDevtoolsModule.instrument()]),
]
Retaining DevTools in production gives you time-travel and state inspection for support issues, but it exposes the full state tree to anyone with the browser extension and adds the history buffer. Removing it eliminates that exposure and the buffer, at the cost of losing live debugging. For a low-traffic app, the performance win from removal is real but modest; the security and memory-hygiene wins are often more compelling.
One diagnostic detail would change the recommendation: roughly how many actions does a typical user session dispatch, and how long does the session stay open? If sessions are short and action counts are low, the DevTools memory overhead is negligible and keeping it for debugging may be fine. If sessions are long-lived with hundreds or thousands of actions, the linear history growth makes removal the safer default.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.