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 🙏

© 2024 – Pkg Stats / Ryan Hefner

slotmap

v0.0.4

Published

slotmap

Downloads

11

Readme

Build Status

Slotmap in Typescript

This was an experiment to see about building something like a multi-value SlotMap as the basis for an Entity Component System in Javascript/Typescript (just for experimental purposes)

It stops short of many things that would be required to tie them together, since I first wanted to see if aligning things with Arrays gave a performance boost (without relying on an unrealistic API).

See Results below :)

In terms of speed - the top priority is iteration over values. Less priority is given to insertion/removal

In terms of features - insert() gives a unique key (within the given slotmap) and can be used for lookups with zero conflicts (until the "generation/version" wraps... but that's a story for another time and isn't relevant to the test here)

There are API's for updating and getting in any order and iterating over the values and/or keys, as well as selectively culling the values to get only what's needed.

Basically - things can be thought of as a structure of arrays, or an array of structures, or a map of structures, and the API supports all of those (just like you can iterate over a native Map's values and destructure objects, or keys or do a lookup by key, but here we're storing things in arrays - and only Arrays + TypedArays, no objects or hashmaps anywhere!).

The maximum number of live keys it can hold is currently around 1MM.

Errors and missing values are expressed with fp-ts, so that's a peer dependency

Inspired by beach_map and EnTT

(but doesn't go near as far as either of those in terms of features or performance)

Results

Success!

When the values are iterated like an ECS, it's significantly better, like 2x better

When the slotmap is treated like a regular map, it's pretty much equal (actually it's faster - but not by as wide a margin)

100 entries:

running benchmark for 100 entries

nativemap keys x 5,015 ops/sec ±0.38% (95 runs sampled)
slotmap keys x 6,182 ops/sec ±1.15% (92 runs sampled)
nativemap values x 6,131 ops/sec ±1.90% (93 runs sampled)
slotmap values x 10,448 ops/sec ±0.87% (90 runs sampled)

Fastest is slotmap values

1000 entries:

nativemap keys x 397 ops/sec ±2.75% (87 runs sampled)
slotmap keys x 539 ops/sec ±0.74% (93 runs sampled)
nativemap values x 599 ops/sec ±0.46% (91 runs sampled)
slotmap values x 1,021 ops/sec ±3.11% (89 runs sampled)

Fastest is slotmap values

Usage

The benchmark has examples, as well as tests - and source has the interface defined at the top of slotmap.ts :)

If you want to use the lib, for whatever reason, it is published to npm under slotmap

TODO

This could be taken to the next level for a proper ECS with a few changes:

  1. Solve the problem of version expiring when add/remove in a tight loop (use beach_map approach instead of EnTT)
  2. Have different slotmaps indexed by the same keys
  3. Ability to add/remove the components, not the entire entry (e.g. by adding/removing on those different slotmaps)