Repository navigation
CSV Parser 4.0.0 - Let's Get Parallel
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.
CSVReadergets aread_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)
- 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
CSVStatremoved, replaced withDataFrameExecutorand improvedDataFrameDataFramecan now be constructed over a subset ofCSVRowobjects, allowing for streaming algorithmsDataFrameExecutoris a thread pool which allows applying arbitrary user supplied functions toDataFrameobjects, simplifying various data cleaning, transformation, and analysis workflows
-Simplechunk_parallel_apply(CSVReader reader)function (defined incsv_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 ofstring_viewin C++20) - Auto-flushing behavior is now a property of
DelimWriteras 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
DataFrameCellandDataFrameColumn.- Allows for more intuitive syntax like
df[6][7] = "new value" - Allows for enhanced/cleaner column iteration
- Allows for more intuitive syntax like
- Edits are now thread-safe and stored in a sparse overlay (O(1) edits without copying entire rows).
DataFrameExecutoris a reusable thread pool (with proper exception handling) that defaults tostd::hardware_concurrency()workerscsv_data_types()rewritten usingchunk_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