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

webgpu-avoid-redundant-state-setting

v0.0.1

Published

check for and/or avoid redundant state setting in WebGPU

Readme

webgpu-avoid-redundant-state-setting

Setting state multiple times can be a source of lost performance. There's overhead in calling from JavaScript into the WebGPU api. There's also no guarantee the implementation optimizes this stuff under the hood.

So, this is an attempt at

  1. Trivially doing it for you

    In this case just add

    import 'https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-avoid-redundant-state-setting.js';

    or

    <script type="module" src="https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-avoid-redundant-state-setting.js"></script>

    To the top of your app and see if there is any perf difference.

    note: there is overhead in checking for redundant state calls, especially for setBindGroup with dynamic offsets as the library has to check each offset so there is some possibility perf will be worse with this library. Measure for yourself or use (2) below to check your own code.

  2. Making it easy to check if you're submitting redundant state

    This way you can optimize your code.

    In this case use

    import 'https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-check-redundant-state-setting.js';

    or

    <script type="module" src="https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-check-redundant-state-setting.js"></script>

    Then check the JavaScript console.

    Note: this assumes you're using requestAnimationFrame to render. If you are using something else to render like requestVideoFrameCallback or setTimeout or other events, look at the source to see how to do this check for your specific situation.

    If you see lots of redundant state setting, refactor your code to avoid it. You can look at the source code of this library for some ideas. The easiest to avoid are redundant setVertexBuffer and setIndexBuffer calls. setBindGroup is harder if it has to check dynamic offsets.

    Important!

    You do NOT need to avoid setting all redundant state. Rather, this library is just meant to check if you're setting 100s or 1000s of redundant state per pass.

Notes

There isn't very much state in WebGPU. The most (all?) state comes in GPURenderPassEncoder and GPUComputePassEncoder. For example, you set bindGroups by calling setBindGroup and those are sticky until you end the pass encoder.

  • compute and render pass state

    • pipeline: set via setPipeline
    • bindGroups: set via setBindGroup
  • render pass state

    • vertexBuffers: set via setVertexBuffer
    • indexBuffer: set via setIndexBuffer
    • viewport: set via setViewport
    • scissor: set via setScissor
    • blendConstant: set via setBlendConstant
    • stencilReference: set via setStencilReference

The one exception is in a render pass, executeBundles resets some of the state, both before and after. The states reset are the bindGroups, vertexBuffers, indexBuffer, and pipeline.

Testing

Live Tests.

During dev, serve the repo as in npx servez . then open a page to http://locahost:8080/test/.

License

MIT