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

@stain-win/obj-pool

v0.0.6

Published

_obj-pool_ is a lightweight JavaScript library for implementing object pooling, a design pattern used to improve performance in applications that require the frequent creation and destruction of objects. Object pooling can significantly reduce memory allo

Downloads

3

Readme

ObjPool

obj-pool is a lightweight JavaScript library for implementing object pooling, a design pattern used to improve performance in applications that require the frequent creation and destruction of objects. Object pooling can significantly reduce memory allocation and garbage collection overhead, leading to better application performance and smoother user experiences. Created for personal project and forked to npm package.

Features

  • Efficient object reuse: obj-pool helps you reuse objects instead of creating new instances, reducing memory allocation and enhancing performance.
  • Customizable pool size: Configure the maximum number of objects in the pool to match usage requirements.
  • Simple API: obj-pool provides a simple and straightforward API for borrowing and returning objects from the pool.

Installation

You can install obj-pool using npm:

npm install @stain-win/obj-pool

Usage

Importing the Library

import { build, buildFactory, Poolable } from '@stain-win/objPool';

Creating a Pool

build<T>(Type: { new(): T }, reserve?: number, recycle?: (o: T) => T): Poolable<T>

Borrowing and Returning Objects

// Borrow an object from the pool
const pooledObject:  = pool.allocate();

// Use the object
// ...
pooledObject.changeSomething('test');
// Return the object to the pool when done
pool.release(pooledObject);

Examples

You can find more usage examples and integration scenarios in the demo app directory of this repository.

const poolDummy: Poolable<Dummy> = build(Dummy, 20, (dummy: Dummy) => {
            dummy.setChangeMe(0);
            return dummy;
        });

const poolDummyFactory: Poolable<Dummy> = buildFactory(() => new Dummy(args));

const dummy: Dummy = poolDummy.allocate();
const dummyF: Dummy = poolDummyFacotry.allocate();

poolDummy.release(dummy);
poolDummyFactory.release(dummyF);

License

This project is licensed under the MIT License.

Acknowledgments

obj-pool was inspired by the concept of object pooling in game development and aims to bring similar performance benefits to a wide range of JavaScript applications. More optimizations coming soon.

Development

This workspace has been generated by Nx, a Smart, fast and extensible build system.

Running tasks

To execute tasks with Nx use the following syntax:

nx <target> <project> <...options>

You can also run multiple targets:

nx run-many -t <target1> <target2>

..or add -p to filter specific projects

nx run-many -t <target1> <target2> -p <proj1> <proj2>

Targets can be defined in the package.json or projects.json. Learn more in the docs.

Want better Editor Integration?

Have a look at the Nx Console extensions. It provides autocomplete support, a UI for exploring and running tasks & generators, and more! Available for VSCode, IntelliJ and comes with a LSP for Vim users.

Ready to deploy?

Just run nx build demoapp to build the application. The build artifacts will be stored in the dist/ directory, ready to be deployed.