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

ds-csv

v1.0.3

Published

Binary parser for big CSV datasets focused on performance

Downloads

2

Readme

ds-csv

Binary parser for big CSV datasets.

Usage

const DATA_SOURCE = "big-dataset.csv";
const CSV = require("ds-csv");

var count = 0;
var parser = new CSV().parseFile(DATA_SOURCE);

parser
  .on("data", record => count++)
  .on("end", () => console.log("finished, number of records: ", count));

API

CSV(options)

Main CSV constructor. It supports the following options for the parser:

bufferSize: amount of data to map into memory. Defaults to 256MB. The total memory usage can be calculated by this value plus a small footprint required by the parser and temporary data (~20MB). A lineal memory footprint is guaranteed.

delimiter: CSV column delimiter. Defaults to , (comma).

escape: value escape character. Defaults to " (double quotes).

CSV#parseFile(file)

Returns a parser for a file in the file system. The parser is a ReadStream working in object mode that provides a single record for each data event. The record is an array of values, one for each column in the CSV. The first data event contains the column names (if present in the file).

file: CSV file to read.

Performance

I wrote this small library after trying the existing CSV parsers without success. I tried the well-known csv module and the other popular fast-csv library but both are focused in customization, while I needed to parse very huge datasets (up to ~4GB). For big datasets, they're really slow. I looked at both codes to try to improve the performance, but it's harder than writing a 60-lines high performance parser.

That said, this parser is blocking in favor of performance. It reads chunks of data of bufferSize size into memory and parses it directly from the buffer. It doesn't perform any String operation which are the most cpu-expensive operations.

I have not serious benchmarks, but it reads 46,264,832 records (~4.2GB file) in about 9.4 minutes in an Intel Core i7 processor. It's a rate of 82030 records/sec.

Extension

If you need a different data source, it should be easy to extend since the parser uses a dataReader abstraction, a generator function that provides the parser with chunks of data until there's no more data to read. You can look at the default file implementation in the lib/buffered_file_reader.js file.