← Back to blog

Performance Optimization Guide

June 9, 2026 by Matteo Bruni

tsParticles Ribbons is designed to be fast out of the box. However, understanding how the animation pipeline works and following a few best practices can help you maintain smooth 60fps rendering even on lower-end devices. This guide covers everything you need to know about ribbon animation performance.

How Ribbon Rendering Works

Under the hood, tsParticles Ribbons uses the HTML5 Canvas 2D API. Each ribbon is a series of connected bezier curves that follow a physics simulation. The rendering pipeline involves three main stages:

The most expensive operation is typically the canvas drawing step, especially when ribbons are long and have many segments. Understanding this helps you make informed decisions about configuration.

Limit Simultaneous Animations

Each call to ribbons() creates a burst of ribbons. Multiple simultaneous bursts multiply the rendering workload. Here's a practical guideline:

// Good: Stagger bursts to avoid peak load
ribbons();
setTimeout(() => ribbons(), 300);
setTimeout(() => ribbons(), 600);

// Better: Use fewer, larger bursts instead
ribbons({
  count: 50, // spawn more ribbons per burst
});

On desktop browsers, 2-3 simultaneous bursts typically maintain 60fps without issues. On mobile devices, limit yourself to 1-2 concurrent animations. If you need more ribbons, increase the count option rather than calling ribbons() multiple times.

Use Custom Canvas for Section Animations

Full-screen canvas overlays are convenient but wasteful when you only need ribbons in a specific area. Using a custom canvas reduces the drawing area significantly:

// Instead of full-screen ribbons
const canvas = document.getElementById('hero-canvas');
const shoot = await ribbons.create(canvas, {
  zIndex: 0,
});

// Only the hero section needs animation
shoot();

A custom canvas that covers 20% of the viewport uses roughly 80% less GPU memory than a full-screen canvas. This is especially important on mobile devices where GPU memory is limited.

Control Ribbon Count

The number of individual ribbons in a burst directly affects rendering performance. Each ribbon is an independent path that must be drawn every frame. The default count is tuned for visual appeal, but you can reduce it for better performance:

ribbons({
  count: 15, // fewer ribbons, less GPU work
});

Reducing from 30 to 15 ribbons typically improves frame rates by 20-30% on lower-end devices while still providing a visually satisfying effect.

Animation Duration

Longer animations mean more frames to render. Keep animation durations reasonable:

For continuous background animations, consider using requestAnimationFrame instead of setInterval to stay in sync with the browser's render cycle:

const duration = 8000;
const animationEnd = Date.now() + duration;

function spawn() {
  if (Date.now() >= animationEnd) return;
  ribbons();
  requestAnimationFrame(() => {
    setTimeout(spawn, 260);
  });
}

spawn();

Mobile Optimization

Mobile devices have less powerful GPUs and tighter memory constraints. Follow these guidelines for mobile-friendly ribbons:

You can detect mobile devices and adjust settings accordingly:

const isMobile = window.matchMedia('(max-width: 768px)').matches;

ribbons({
  count: isMobile ? 12 : 25,
});

Avoiding Layout Thrashing

Ribbon canvases are positioned using CSS. Avoid forcing layout recalculations during animations by:

tsParticles handles most of these optimizations automatically, but if you're using custom canvases, ensure these CSS properties are set.

Measuring Performance

Use your browser's DevTools to monitor animation performance:

A well-optimized ribbon animation should use less than 5ms of CPU time per frame, leaving plenty of budget for your page content and interactions.

Summary

Performance optimization for ribbon animations comes down to three principles: minimize the rendering area, limit concurrent animations, and keep ribbon counts reasonable. Following the guidelines in this guide will ensure smooth, jank-free ribbon animations across all devices.

For more tips, check out the customization guide or explore the interactive playground to experiment with different configurations.