Skip to content

CSV Parser 4.0.0 - Let's Get Parallel

Choose a tag to compare

@vincentlaucsb vincentlaucsb released this 26 Apr 04:08
· 118 commits to master since this release
b603042

Overview

CSV files are the format which refuse to die. Despite its many warts, CSVs are the most compact text-based format for storing tabular data, and thus are a natural dumping ground for SQL databases and many other workflows.

This release ties together numerous loose ends to make the library more coherent as a general purpose ETL library for CSV files.

  • CSVReader gets a read_chunk() method that allows for reading chunks of rows at a time
    • Helpful for column-parallel streaming algorithms. Based on a program for generating SQL table information for a CSV, this provided a 50mb/s boost over a simple read_row() (iterator)
  • CSVStat removed, replaced with DataFrameExecutor and improved DataFrame
    • DataFrame can now be constructed over a subset of CSVRow objects, allowing for streaming algorithms
    • DataFrameExecutor is a thread pool which allows applying arbitrary user supplied functions to DataFrame objects, simplifying various data cleaning, transformation, and analysis workflows
      -Simple chunk_parallel_apply(CSVReader reader) function (defined in csv_utility.hpp) may be used as shorthand for simpler column-parallel operations

DelimWriter: 40mb/s -> 100mb/s

By adding SIMD acceleration for escaping logic, and buffering text before piping them to std::ostream, I was able to achieve very dramatic speed-ups for CSV writing.

  • Added a write_rows() method for efficiently writing collections of rows (and collections of rows of string_view in C++20)
  • Auto-flushing behavior is now a property of DelimWriter as opposed to being set at compile time

Improved JSON Conversion

  • Fixed a bug in DataFrame's JSON serialization methods that did not respect edits
  • Added various optimizations

DataFrame improved/CSVStat removed

CSVStat was powerful for basic statistics but too rigid for arbitrary user-defined operations. Its spirit lives on in the new DataFrameExecutor + streaming DataFrame support.

  • Added DataFrameCell and DataFrameColumn.
    • Allows for more intuitive syntax like df[6][7] = "new value"
    • Allows for enhanced/cleaner column iteration
  • Edits are now thread-safe and stored in a sparse overlay (O(1) edits without copying entire rows).
  • DataFrameExecutor is a reusable thread pool (with proper exception handling) that defaults to std::hardware_concurrency() workers
  • csv_data_types() rewritten using chunk_parallel_apply()
    • I was able to generate a full PostgreSQL schema for a 11GB file in 30 seconds without interrupting the YouTube video I was watching

tl;dr: The DataFrame is not trying to replicate everything Pandas or Apache Arrow does. It's goal is to:

  • Make simple edits quick and painless
  • Act as a high performance streaming bridge to other libraries, formats, or SQL databases

Benchmarks

Added proper benchmarks against other popular C++ CSV libraries. See the /benchmarks folder for details.

Special thanks to the Microsoft Visual C++ team

For having malloc() default to 16-byte alignment even when compiling with 32-byte SIMD instructions (/arch:AVX2) causing lots of fun and exciting heap corruption issues that don't affect clang or g++ because <redacted>.

What's Changed

  • CSV Parser 4.0.0 - Benchmarks, DataFrame gets parallelized, MSVC AV2 Fixes by @vincentlaucsb in #309

Full Changelog: 3.5.1...4.0.0