Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
A fast fifo implementation similar to the one powering nextTick in Node.js core
The fast-fifo npm package is a high-performance, zero-dependency queue implementation for JavaScript. It is designed to be a fast FIFO (first-in-first-out) queue structure that can be used in various scenarios where queue operations are required, such as task scheduling, event handling, or data processing pipelines.
Queue Creation
This feature allows for the creation of a new queue instance. The Queue class is imported from the fast-fifo package and instantiated to create a new queue.
const Queue = require('fast-fifo');
const q = new Queue();
Enqueue
This feature is used to add an item to the end of the queue. The push method is called on the queue instance with the item to be added as an argument.
q.push('some data');
Dequeue
This feature is used to remove and return the item at the front of the queue. The shift method is called on the queue instance to dequeue the item.
const item = q.shift();
Peek
This feature allows you to look at the item at the front of the queue without removing it. The head method is called on the queue instance to retrieve the first item.
const firstItem = q.head();
Queue Length
This feature provides the current number of items in the queue. The length property of the queue instance gives the count of items.
const queueLength = q.length;
This package is similar to fast-fifo in that it provides a queue mechanism, but it is specifically designed for queuing microtasks within the same tick of the event loop, rather than for general FIFO queue data structures.
p-queue is a promise-based queue with concurrency control. It is similar to fast-fifo in managing tasks in a queue, but it also allows for setting concurrency limits and prioritizing tasks.
bee-queue is a simple, fast, robust job/task queue for Node.js, backed by Redis. It is similar to fast-fifo in that it manages a queue of tasks, but it is more feature-rich, including persistence, retries, and job events.
Part of the async utility module, async.queue provides a queue implementation that can process tasks with configurable concurrency. It is similar to fast-fifo in managing tasks in a queue but focuses on asynchronous task processing.
A fast fifo implementation similar to the one powering nextTick in Node.js core
npm install fast-fifo
Uses a linked list of growing fixed sized arrays to implement the FIFO to avoid allocating a wrapper object for each item.
const FIFO = require('fast-fifo')
const q = new FIFO()
q.push('hello')
q.push('world')
q.shift() // returns hello
q.shift() // returns world
q = new FIFO()
Create a new FIFO.
q.push(value)
Push a value to the FIFO. value
can be anything other than undefined.
value = q.shift()
Return the oldest value from the FIFO.
bool = q.isEmpty()
Returns true
if the FIFO is empty and false otherwise.
value = q.peek()
Return the oldest value from the FIFO without shifting it out.
len = q.length
Get the number of entries remaining in the FIFO.
Included in bench.js is a simple benchmark that benchmarks this against a simple linked list based FIFO.
On my machine the benchmark looks like this:
fifo bulk push and shift: 2881.508ms
fifo individual push and shift: 3248.437ms
fast-fifo bulk push and shift: 1606.972ms
fast-fifo individual push and shift: 1328.064ms
fifo bulk push and shift: 3266.902ms
fifo individual push and shift: 3320.944ms
fast-fifo bulk push and shift: 1858.307ms
fast-fifo individual push and shift: 1516.983ms
YMMV
MIT
FAQs
A fast fifo implementation similar to the one powering nextTick in Node.js core
The npm package fast-fifo receives a total of 6,717,123 weekly downloads. As such, fast-fifo popularity was classified as popular.
We found that fast-fifo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.