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 🙏

© 2026 – Pkg Stats / Ryan Hefner

farm-plugin-static-opt

v0.2.0

Published

Static optimization plugin for FarmFE — constant folding, loop unrolling, dead branch elimination at compile time

Readme

farm-plugin-static-opt

Static optimization plugin for FarmFE — performs compile-time optimizations that JS engines would otherwise do at runtime.

Install

npm install farm-plugin-static-opt

Dependencies: This plugin uses core-ast-ts internally. Installed automatically.

Concept

This is not minification. This is compile-time static optimization — doing at build time what JS engines do at runtime:

  • Constant folding: 2 + 35, "hello" + " world""hello world"
  • Dead branch elimination: if (true) { A } else { B }A
  • Loop unrolling: for (let i = 0; i < 3; i++) { ... } → body × 3

This makes the output code smaller and faster before any minifier even sees it.

Usage

import staticOpt from 'farm-plugin-static-opt'

export default {
  plugins: [staticOpt()],
}

With options:

staticOpt({
  constantFolding: true,      // fold 2+3 → 5 (default: true)
  deadBranchElimination: true, // remove if(false) branches (default: true)
  loopUnrolling: true,         // unroll small loops (default: true)
  maxUnroll: 8,                // max trip count for unrolling (default: 8)
})

Optimizations

Constant Folding

Arithmetic, logical, and bitwise expressions with all-literal operands are evaluated at compile time:

// Before
const area = 3.14 * 4 * 4
const flag = true && false
const mask = 0xFF & 0x0F

// After
const area = 50.24
const flag = false
const mask = 15

String concatenation:

// Before
const url = "/api" + "/v1" + "/users"

// After
const url = "/api/v1/users"

Dead Branch Elimination

If/else and ternary with constant conditions:

// Before
if (true) {
  setupApp()
} else {
  setupFallback()
}

// After
setupApp()
// Before
const mode = false ? 'production' : 'development'

// After
const mode = 'development'

Works especially well combined with farm-plugin-selective — after selective compilation replaces conditions with literals, this plugin eliminates the dead branches.

Loop Unrolling

For-loops with known bounds and small trip counts:

// Before
for (let i = 0; i < 3; i++) {
  console.log(i)
}

// After
{
  console.log(0)
  console.log(1)
  console.log(2)
}

With step:

// Before
for (let i = 0; i < 6; i += 2) {
  process(i)
}

// After
{
  process(0)
  process(2)
  process(4)
}

Only unrolls loops with:

  • Literal start, end, and step values
  • Trip count ≤ maxUnroll (default: 8)
  • Simple i++/i--/i += N/i -= N update

HMR

Optimizations are re-applied on file changes.

License

MIT