{"id":16591,"library":"yapool","title":"yapool: Simple Object Pool","description":"yapool is a minimalist JavaScript object pooling library, currently at version 1.0.0. It provides a basic linked-list implementation for managing reusable objects, focusing on extreme simplicity over feature richness. Unlike more comprehensive alternatives, yapool offers a 'dead-simple' API for adding and removing objects. Its primary differentiator is its minimal footprint and straightforward approach, making it suitable for scenarios where `n` (the number of objects in the pool) is small. Developers should be aware that operations like `remove` have `O(n)` complexity, which limits its applicability for very large lists. Given its simplicity and the project's age (last published in 2014), its release cadence is very stable or infrequent, suggesting a maintenance-only status rather than active feature development.","status":"maintenance","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/isaacs/yapool","tags":["javascript"],"install":[{"cmd":"npm install yapool","lang":"bash","label":"npm"},{"cmd":"yarn add yapool","lang":"bash","label":"yarn"},{"cmd":"pnpm add yapool","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"yapool is a CommonJS module and exports the Pool constructor as its default.","symbol":"Pool","correct":"const Pool = require('yapool')"},{"note":"When importing a CommonJS module in an ES Module context, the `module.exports` is typically treated as the default import. Named imports (`{ Pool }`) will likely fail for this package unless transpiled.","wrong":"import { Pool } from 'yapool'","symbol":"Pool","correct":"import Pool from 'yapool'"}],"quickstart":{"code":"const Pool = require('yapool');\n\nconst myObjectPool = new Pool();\n\n// Add objects to the pool\nconst obj1 = { id: 1, value: 'alpha' };\nconst obj2 = { id: 2, value: 'beta' };\nmyObjectPool.add(obj1);\nmyObjectPool.add(obj2);\n\nconsole.log(`Pool length after adding: ${myObjectPool.length}`); // Expected: 2\n\n// Remove an object from the pool\nmyObjectPool.remove(obj1);\n\nconsole.log(`Pool length after removing obj1: ${myObjectPool.length}`); // Expected: 1\n\n// Attempt to remove an object not in the pool (it will be a no-op)\nconst obj3 = { id: 3, value: 'gamma' };\nmyObjectPool.remove(obj3);\n\nconsole.log(`Pool length after attempting to remove obj3: ${myObjectPool.length}`); // Expected: 1\n\n// The remaining object in the pool is obj2\n// (Note: yapool does not provide a way to 'get' an object, only add/remove)","lang":"javascript","description":"Demonstrates initializing a new Pool, adding and removing objects, and checking the pool's length."},"warnings":[{"fix":"For large pools or performance-critical applications, consider object pool implementations backed by hash maps or other data structures that offer `O(1)` or `O(log n)` average-case performance for lookups and deletions.","message":"The `remove` operation, and potentially `add` if it checks for existence, has `O(n)` time complexity. This makes `yapool` unsuitable for applications requiring high performance with very large object pools, as iterating through the linked list to find an object can become slow.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Evaluate if yapool's minimal API meets your needs. For more advanced pooling scenarios, look for libraries that offer factory functions, max limits, and lifecycle hooks.","message":"yapool is a bare-bones implementation lacking common features found in more robust object pooling libraries. It does not provide mechanisms for creating new objects when the pool is empty (factory functions), limiting the pool to pre-existing objects. It also lacks features like maximum pool size, object lifecycle callbacks (e.g., `onReturn`, `onBorrow`), or health checks. This requires manual management of object creation and disposal.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `import Pool from 'yapool'` when consuming in an ESM project. Be aware that older CommonJS modules might affect modern build optimizations. If strict ESM compatibility or advanced bundling is critical, consider a natively ESM object pool.","message":"As a CommonJS-first package published in 2014, `yapool` may not fully support or be optimized for modern ES Module (ESM) environments and bundlers. While `import Pool from 'yapool'` typically works, named imports might fail, and bundlers might not be able to perform effective tree-shaking, potentially leading to larger bundle sizes if only parts of the module were theoretically used (though `yapool` is small).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure you are using the correct import syntax for a CommonJS default export in ESM: `import Pool from 'yapool';`. If in CommonJS, use `const Pool = require('yapool');`.","cause":"Attempting to use `new Pool()` after importing incorrectly from a CommonJS module in an ES Module context, or attempting to use a named import that doesn't exist.","error":"TypeError: Pool is not a constructor"},{"fix":"Install the package using npm: `npm install yapool`. Verify the package name in your `package.json` and in your `import` or `require` statement.","cause":"The `yapool` package has not been installed, or the import/require path is incorrect.","error":"Error: Cannot find module 'yapool'"}],"ecosystem":"npm"}