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

fast-read-file

v1.0.2

Published

A utility to efficiently and safely read a large number of files

Downloads

2

Readme

fast-read-file: A microoptimized file reader

Overview

fast-read-file is a performant, EMFILE-safe file reader exposing a simple promise-based API. Surprisingly, the built-in node:fs read file APIs (to various degrees) leave a fair amount of performance on the table. Every effort has been made to choose the "performance" option behind the top-level API of this library. By default, fast-read-file will allocate a pool of twenty-four 64K Buffers. Each request to readFile will then wait for one of these Buffers to be available, and optimistically attempt to read the file into that buffer, resorting to an additional sized file read operation if required. Accordingly, this library is—by default—tuned to read large numbers of <64k files, but via the rawReadFile API, tuning to a particular usecase can be achieved.

Benchmarks

From node 18.9.0 on a 2019 Intel MacBook Pro (2.4 GHz/32GB/1TB):

fs.readFileSync (mixed) x 3.44 ops/sec ±2.76% (21 runs sampled)
fast-read-file (mixed) x 7.65 ops/sec ±2.93% (41 runs sampled)
pooled fs.readFile (mixed) x 6.40 ops/sec ±3.00% (35 runs sampled)
pooled promisified fs.readFile (mixed) x 6.57 ops/sec ±3.55% (36 runs sampled)
pooled fs.promises.readFile (mixed) x 4.29 ops/sec ±1.49% (25 runs sampled)
gracefulFs.readFile (mixed) x 6.24 ops/sec ±2.04% (34 runs sampled)

Usage

Basic usage:

import { readFile } from "fast-read-file";

await readFile("./path/to/file.txt"); // Return a Buffer of the file

If you'd like to customize the working Buffer pool or sizes in use, the raw file reader is available to offer no allocation overhead and full control. For optimal performance, you'll want to avoid small (<4K) buffers. 64K provides a reasonable starting point for most filesystem reads.

import { readFile } from "fast-read-file/raw";

const workingBuffer = Buffer.allocUnsafe(64 * 1024);

await readFile(workingBuffer, "./path/to/file.txt"); // Return a Buffer of the file