Skip to main content
Reatom is designed for exceptional performance in complex applications. The more sophisticated your app, the faster Reatom performs compared to alternatives. This guide covers performance optimization patterns and best practices.

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

For large lists with editable items, atomize each item. This ensures editing one item doesn’t trigger re-renders of all items.

List Atomization Example

Memoization with memo

Use memo inside computed atoms or actions to avoid expensive recomputations when only part of the dependencies change.
Important: memo uses only the first callback provided. Don’t rely on closure variables that change between calls. Use stable functions or provide a custom key parameter.

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:
  1. They have at least one subscriber
  2. Their dependencies have changed
Use computed atoms with withAsyncData for data fetching. They automatically activate when subscribed (e.g., when a component mounts) and deactivate when unsubscribed.

Optimizing Re-renders in Components

Use reatomComponent for Automatic Optimization

Read Only What You Need

Abort Strategies for Performance

Use withAbort 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

The logger shows:
  • 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.
Avoid premature optimization. Profile your application first, then apply these patterns where they provide measurable benefits.

Common Performance Anti-Patterns

Creating Atoms in Render

Not Using withAsyncData for Fetching

Over-subscribing

Further Reading