npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

raf-signal

v1.0.6

Published

Shared requestAnimationFrame scheduler

Readme

raf-signal

Shared requestAnimationFrame scheduler

A tiny scheduler that coalesces all requestAnimationFrame subscribers into one frame loop.

Reduce main thread overhead. Eliminate redundant rAF calls. Get predictable, stable frame updates.

Why raf-signal?

Browsers allow to call requestAnimationFrame() anywhere: UI components, physics systems, stores, animations, WebGL render loops.

Problem: each call schedules its own micro task, its own frame callback and its own cancellation cost.

With many independent subscribers (React components, stores, animations), this leads to:

  • excessive main thread overhead
  • jank when callbacks pile up
  • unpredictable frame budgets
  • wasted CPU + battery

raf-signal fixes this by creating ONE shared animation loop and broadcasting the frame timestamp to all subscribers.

Whether you register 1 callback or 10,000, the browser only runs one rAF cycle.

Features

  • Single rAF loop for any number of subscribers
  • Automatic start/stop (zero overhead when idle)
  • Pause/resume built-in
  • once() for one time frame execution
  • Zero dependencies

Installation

npm install raf-signal

Usage

Subscribe to frame updates

import { subscribe } from "raf-signal";

const sub = subscribe((time) => {
  console.log("frame:", time);
});

sub.unsubscribe();

Run one frame only

import { once } from "raf-signal";

once((time) => console.log("first frame:", time));

Pause & resume

import { pause, resume } from "raf-signal";

pause();
resume();

Get active subscriber count

import { getSubscriberCount } from "raf-signal";

console.log(getSubscriberCount());

API

type RafCallback = (time: number) => void;

interface RafSubscription {
  unsubscribe(): void;
}

function subscribe(callback: RafCallback): RafSubscription;
function once(callback: RafCallback): void;
function pause(): void;
function resume(): void;
function getSubscriberCount(): number;

Game Dev Use Cases

Game engines are built on centralized frame loops. When you build modular gameplay systems in JavaScript environments, each system tends to request its own rAF:

  • physics update
  • sprite updates
  • animation interpolators
  • camera tracking
  • particle system updates

Individually they all call requestAnimationFrame() leading to uncoordinated frame processing.

With raf-signal, we get:

  • one unified tick
  • deterministic ordering
  • less frame drift
  • lower input latency
  • more predictable render budget
  • fewer GC pauses

Example: central game loop

import { subscribe } from "raf-signal";

const systems = [updatePhysics, updateParticles, updateEnemies, updateCamera];

subscribe((time) => {
  for (const system of systems) system(time);
});

Acknowledgements

Inspired by frame loop consolidation patterns used in game engines and Canvas based animations.