Why Reatom is Fast
Reatom achieves excellent performance through several key design decisions:- Explicit reactivity without proxies - Direct atom function calls are faster than proxy access
- Lazy evaluation - Computed atoms only recalculate when subscribed and dependencies change
- Atomization patterns - Fine-grained control over what triggers updates
- Immutable data structures - Efficient change detection with reference equality
- Controlled reactive creation - You define exactly what should be reactive
Check out this benchmark comparing Reatom to other state managers in complex computation scenarios. Reatom outperforms MobX for mid-range numbers while handling more features.
Atomization Pattern
Atomization is the practice of splitting state into granular atoms to minimize unnecessary updates and computations.Bad: Single Large Object
Good: Atomized Structure
List Atomization Example
Memoization with memo
Use memo inside computed atoms or actions to avoid expensive recomputations when only part of the dependencies change.
Advanced memo with Custom Keys
Using memoKey for Services
Create expensive objects once and reuse them across atom executions with memoKey.
Lazy Computed Atoms
Computed atoms are lazy by default - they only run when:- They have at least one subscriber
- Their dependencies have changed
Optimizing Re-renders in Components
Use reatomComponent for Automatic Optimization
Read Only What You Need
Abort Strategies for Performance
UsewithAbort to cancel outdated requests and prevent unnecessary work.
The
withAbort extension prevents race conditions and saves resources by aborting unnecessary async operations.First-in-win Strategy
Selective Equality with withMemo
Prevent updates when new state is equivalent to old state.
Performance Monitoring
Use connectLogger for Insights
- Which atoms are updating
- Dependency chains causing updates
- Timing information for async operations
DevTools Integration
Reatom DevTools provides visual inspection of your state graph and update patterns. See the DevTools guide for setup instructions.Best Practices Summary
1
Atomize your state
Split large objects into granular atoms for fine-grained reactivity.
2
Use memo for expensive computations
Wrap expensive operations in
memo() inside computed atoms to avoid unnecessary recalculations.3
Leverage lazy evaluation
Use
computed + withAsyncData for data fetching - they only run when subscribed.4
Apply abort strategies
Use
withAbort() on async operations to cancel outdated work.5
Read selectively
Extract specific properties into dedicated computed atoms instead of reading entire objects.
6
Monitor in development
Use
connectLogger and DevTools to identify performance bottlenecks.Common Performance Anti-Patterns
Creating Atoms in Render
Not Using withAsyncData for Fetching
Over-subscribing
Further Reading
- Atomization Recipes - More atomization patterns
- Benchmark Results - Performance comparisons
- DevTools Guide - Visual performance monitoring