Virtual DOM Performance
Template System
Dioxus uses a template-based virtual DOM that pre-compiles static structure:packages/core/src/nodes.rs:40-89
Memoization
Components automatically memoize props to prevent unnecessary re-renders:PartialEq on props to enable automatic memoization.
Keyed Lists
Use keys for efficient list diffing:packages/core/tests/diff_keyed_list.rs
Signal Optimization
Granular Reactivity
Signals provide fine-grained reactivity:Avoid Over-Subscription
Don’t read signals unnecessarily:Computed Values
Useuse_memo for expensive derived state:
Component Architecture
Scope Height Optimization
Dioxus renders scopes top-to-bottom by height. Keep frequently updated components shallow:packages/core/src/virtual_dom.rs:379-404
Component Splitting
Split large components to minimize re-render scope:Async Performance
Task Management
Avoid spawning too many tasks:Suspense Boundaries
Use suspense to avoid blocking the UI:Resource Deduplication
Memory Optimization
Avoid Large Clones
Drop Unused Resources
Scope Context Sharing
Use context to avoid prop drilling without performance cost:Rendering Performance
Batch Updates
Debounce User Input
Virtual Scrolling
For large lists, render only visible items:Build Optimization
Release Builds
Always use release mode for production:- LLVM optimizations
- Dead code elimination
- Inlining
- LTO (Link Time Optimization)
WASM Optimization
For web builds, optimize WASM size:Asset Optimization
Use manganis for automatic asset optimization:Profiling
Chrome DevTools
For web builds, use Chrome’s Performance profiler:- Open DevTools (F12)
- Go to Performance tab
- Click Record
- Interact with your app
- Stop recording
- Analyze flame graph
Tracing
Enable tracing for detailed logs:- Component renders
- Scope creation/destruction
- Task execution
- Event handling
packages/core/src/virtual_dom.rs:307-331
Custom Metrics
Benchmarking
Create benchmarks to measure performance:Best Practices
- Measure First: Profile before optimizing
- Use Keys: Always key dynamic lists
- Memoize Props: Implement
PartialEqon props - Granular Signals: Use signals for fine-grained reactivity
- Batch Updates: Group multiple state changes
- Lazy Loading: Use suspense for async content
- Optimize Assets: Use manganis for asset optimization
- Release Builds: Always benchmark in release mode
Common Pitfalls
- Over-optimization: Don’t optimize without profiling
- Premature Memoization: Simple components don’t need memoization
- Too Many Signals: Signals have overhead, use sparingly
- Large Props: Avoid cloning large data structures
- Blocking Async: Don’t block in async tasks
Additional Resources
- Core architecture:
notes/architecture/01-CORE.md - Signals architecture:
notes/architecture/04-SIGNALS.md - VirtualDOM source:
packages/core/src/virtual_dom.rs - Diff algorithm:
packages/core/src/diff/