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

fuzion

v0.2.0

Published

High-performance shortcut fusion for JavaScript and TypeScript array operations

Readme

Fuzion

Runtime implementation of shortcut fusion for JavaScript and TypeScript

Fuzion is an optimization technique that merges multiple array operations into a single loop, eliminating intermediate data structures and providing significant performance improvements over chained native methods.

📖 What is Shortcut Fusion?

Definition (haskell docs): Shortcut fusion is an optimizer method that merges some function calls into one. E.g., map f * map g can be substituted by map (f * g), and filter p * filter q can be substituted by filter (\x -> q x && p x). It can also help to remove intermediate data structures. E.g., computing sum [1..n] does not require an explicit list structure, and the expression is actually translated into a simple loop.

🛠️ API

  • fuzion(input, ...operators) - Main function for shortcut fusion
  • map(fn) - Transform each element
  • filter(predicate) - Include elements that pass the test
  • forEach(fn) - Execute function for each element
  • take(count) - Limit result to first N elements

💡 Usage Examples

Basic Operations

import { fuzion, map, filter, take } from 'fuzion';

// Simple transformation
const doubled = fuzion([1, 2, 3, 4, 5], map(x => x * 2));
// Result: [2, 4, 6, 8, 10]

// Filter and transform
const evensDoubled = fuzion([1, 2, 3, 4, 5],
  filter(x => x % 2 === 0),
  map(x => x * 2)
);
// Result: [4, 8]

// Complex chain with early exit
const result = fuzion([1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
  map(x => x * 2),           // Double each number
  filter(x => x > 5),         // Keep only > 5
  take(3)                     // Take first 3 results
);
// Result: [6, 8, 10] - stops processing after finding 3 results

TypeScript Support

Fuzion provides full TypeScript inference with up to 13 operator chains:

interface User {
  id: number;
  name: string;
  age: number;
}

const users: User[] = [
  { id: 1, name: 'Alice', age: 25 },
  { id: 2, name: 'Bob', age: 30 },
  { id: 3, name: 'Charlie', age: 35 }
];

// Full type inference
const adultNames = fuzion(users,
  filter(user => user.age >= 30),    // TypeScript knows this is User[]
  map(user => user.name)             // TypeScript infers string[]
);
// Type: string[] = ['Bob', 'Charlie']

⚡ Performance

  • MAP-only chains: Competitive with chained native (often faster)
  • TAKE operator: Up to 58x faster than chained native with early exit
  • Memory efficient: No intermediate arrays created
  • Optimized constants: Numeric operator types for faster comparisons
  • Lightweight: Only 599 B gzipped (tree-shakeable for smaller bundles)

| Operation Type | Performance vs Chained Native | Notes | |----------------|------------------------------|-------| | MAP-only chains | 1.03x faster | Pre-allocated arrays | | TAKE operations | Up to 58x faster | Early exit optimization | | Mixed operations | 1.18x slower | Function call overhead | | Single operations | 1.18-1.81x slower | Baseline overhead |

Performance Comparison

Traditional chaining (creates intermediate arrays):

const result = array
  .map(x => x * 2)      // Creates new array
  .map(x => x + 1)      // Creates another array
  .filter(x => x > 5);  // Creates final array

Fuzion (single loop, no intermediate arrays):

const result = fuzion(array,
  map(x => x * 2),      // Fused into single loop
  map(x => x + 1),      // No intermediate arrays
  filter(x => x > 5)    // Direct processing
);

Real-world example:

const data = Array.from({ length: 10000 }, (_, i) => i + 1);

// Chained native (slower - creates intermediate arrays)
const chained = data
  .map(x => x * 2)
  .map(x => x + 1)
  .filter(x => x > 5)
  .slice(0, 100);

// Fuzion (faster - single loop with early exit)
const fused = fuzion(data,
  map(x => x * 2),
  map(x => x + 1),
  filter(x => x > 5),
  take(100)
);

🎯 When to Use Fuzion

✅ Great for:

  • Complex data transformation pipelines
  • Operations with take() for early exit
  • MAP-only chains (often faster than native)
  • Memory-constrained environments
  • Functional programming patterns

⚠️ Consider alternatives for:

  • Simple single operations (use native methods)
  • Performance-critical single loops (manual implementation)
  • Very small arrays (< 100 elements)

🔧 Installation

npm install fuzion
# or
yarn add fuzion

📄 License

MIT License - see LICENSE file for details.