One thousand components

Build high-performance applications that efficiently render and animate thousands of components using Aurelia's optimized rendering pipeline.

Learn how to build high-performance Aurelia applications that can smoothly render and animate thousands of components simultaneously. This tutorial demonstrates rendering techniques, performance optimization, and best practices for extreme-scale UIs using an animated visualization with 10,000+ SVG elements.

Why This Is an Advanced Scenario

Rendering thousands of components challenges:

  • Rendering performance - Minimizing DOM updates

  • Memory efficiency - Managing thousands of objects

  • Animation smoothness - 60 FPS with heavy workloads

  • Data structures - Efficient updates and mutations

  • Change detection - Smart dirty checking strategies

  • Browser limits - Working within DOM constraints

This tutorial demonstrates:

  • Efficient repeat.for usage at scale

  • RAF (Request Animation Frame) scheduling

  • Batch DOM updates

  • Object pooling and reuse

  • SVG performance optimization

  • Profiling and debugging techniques

The Demo

We'll build an interactive visualization that:

  1. Renders 10-10,000 animated SVG rectangles

  2. Transitions between 4 different layout patterns (Grid, Wave, Spiral, Phyllotaxis)

  3. Maintains 60 FPS throughout

  4. Uses interpolated colors for visual appeal

  5. Provides interactive controls for component count

Live example: Based on the InfernoJS 1k Components benchmark.

Project Setup

Part 1: Layout Algorithms

First, create the mathematical layout strategies:

Key Insights:

  • Phyllotaxis: Golden angle spiral (sunflower seed pattern)

  • Grid: Simple square grid layout

  • Wave: Sinusoidal wave pattern

  • Spiral: Logarithmic spiral

Part 2: Point Data Model

Create the data model that each rendered element uses:

Performance Techniques:

  1. Pre-compute all layouts - Every point knows all 4 positions

  2. Interpolation - Smooth transitions between layouts

  3. Static properties - Share animation state across all points

  4. Integer truncation - ~~value faster than Math.floor()

Part 3: Main Application Component

Performance Techniques:

  1. Persistent RAF - Single animation loop for all points

  2. Batch updates - Update all points together

  3. Smart array manipulation - Reuse existing points when possible

  4. Splice optimization - Remove from end (faster than shift)

Part 4: Template

Template Optimizations:

  • SVG over HTML - Faster rendering for graphics

  • Minimal bindings - Only transform and fill

  • Debounced input - Prevent excessive updates

  • Single container - One <g> for all rectangles

Part 5: Styling

CSS Performance:

  • will-change: transform - GPU acceleration hint

  • transform over left/top - Composite-only changes

  • Minimal reflows - Absolute positioning

  • No transitions - JavaScript handles animation

Performance Analysis

Profiling Results

Components
FPS
Memory
DOM Nodes

100

60

~5MB

101

1,000

60

~15MB

1,001

5,000

58-60

~45MB

5,001

10,000

50-55

~80MB

10,001

Bottlenecks

  1. Layout calculations - O(n) per frame

  2. String concatenation - transform attribute

  3. Color interpolation - Viridis lookup

  4. DOM updates - Bindings update detection

Optimization Strategies

1. Object Pooling

2. Virtualization

3. Web Workers

4. Canvas Rendering

Browser DevTools Profiling

Performance Tab

  1. Record during animation

  2. Look for:

    • Frame rate drops (<60 FPS)

    • Long tasks (>16ms)

    • Excessive garbage collection

    • Layout thrashing

Memory Tab

  1. Take heap snapshot

  2. Check:

    • Retained size of Point instances

    • Detached DOM nodes

    • String allocations (transform)

Rendering Tab

Enable:

  • Paint flashing - See repaint regions

  • Layout shift regions - Detect reflows

  • Layer borders - Check compositing

Common Pitfalls

1. String Allocation Churn

Bad:

Good:

2. Unnecessary Re-renders

Bad:

Good:

3. Memory Leaks

Bad:

Good:

Real-World Applications

Data Visualization

  • Scatter plots with 10k+ data points

  • Network graphs with thousands of nodes

  • Real-time sensor data displays

Gaming

  • Particle systems

  • Sprite-based animations

  • Tilemap renderers

Enterprise

  • Large data tables with virtual scrolling

  • Real-time dashboards

  • Log viewers with thousands of entries

Key Takeaways

  1. Pre-compute when possible - Don't calculate in getter

  2. Batch updates - Use batch

  3. Profile religiously - Measure, don't guess

  4. Consider alternatives - Canvas for 50k+ elements

  5. Smart data structures - Object pools, efficient arrays

  6. GPU acceleration - Use transform and will-change

Resources

Next Steps

  • Add Web Worker support for calculations

  • Implement Canvas fallback for 50k+ points

  • Add more layout algorithms

  • Benchmark against other frameworks

  • Profile memory usage patterns

  • Implement object pooling

Last updated

Was this helpful?