MotherDuck
YouTube
DuckDB 2.0: How to Speed Up Your Workloads
DuckDB 2.0 introduces asynchronous I/O that splits work into a CPU‑oriented thread pool and a larger IO thread pool, giving a 3× boost when reading cloud data and a 30‑% boost from local disk. The new external file cache spill flag lets the engine spill out‑of‑memory data to disk instead of evicting it, dramatically speeding repeated reads of large files. Partitioned and sorted Parquet writes can now be parallelized, and the async copy API is being extended to support more stages. DuckDB’s extension system lets you embed languages like Python, Lua, or Rust, enabling custom UDFs and richer workflows while keeping the core engine lightweight and portable.
Insights
1. Async I/O Thread Pool Design
1.1 DuckDB 2.0 uses two separate thread pools: a CPU pool matching the number of cores and an IO pool that is typically four times larger.
1.2 The IO pool pre‑fetches data from cloud or disk, allowing the CPU to work on other tasks while waiting for network or disk latency.
1.3 This architecture yields up to a 3× speedup for cloud reads and ~30% for local SSD reads.
2. External File Cache Spill
2.1 When memory is low, DuckDB can spill data to a local disk cache instead of discarding it.
2.2 The cache is validated against the source to avoid stale data, so subsequent reads hit the disk instead of the network.
2.3 This reduces repeated network fetch times from seconds to milliseconds for large Parquet files.
3. Parallel Parquet Writes and Async Copy
3.1 DuckDB now supports writing partitioned and sorted Parquet files, enabling parallel output streams.
3.2 The async copy API is being extended to asyncify more stages of the write pipeline, though end‑to‑end async writes are not yet complete.
3.3 Using larger partitions and the partitioned write mode can give immediate performance gains.
4. Extension Mechanism for Custom Code
4.1 DuckDB’s C API allows building extensions in languages like C++, Rust, or embedding interpreters for Lua or JavaScript.
4.2 Python can be used via the map function or scalar UDFs that process batches of rows using Arrow.
4.3 This lets developers write high‑performance logic inside the database without leaving the process.
5. Tuning Async Threads
5.1 The async_threads configuration controls the size of the IO thread pool; increasing it can help when network latency is high.
5.2 On slower cloud providers like Azure Blob, raising async_threads can offset the latency difference.
5.3 Careful tuning balances memory usage and parallelism; too many threads may waste resources.
6. Cloud Provider Performance Variability
6.1 Benchmarks show that S3, Azure Blob, and GCS have similar performance, with Azure slightly slower on average.
6.2 The async I/O model mitigates differences by saturating available bandwidth, but tuning may still be needed.
6.3 Users should run their own benchmarks to validate performance in their specific environment.
1.1 DuckDB 2.0 uses two separate thread pools: a CPU pool matching the number of cores and an IO pool that is typically four times larger.
1.2 The IO pool pre‑fetches data from cloud or disk, allowing the CPU to work on other tasks while waiting for network or disk latency.
1.3 This architecture yields up to a 3× speedup for cloud reads and ~30% for local SSD reads.
2. External File Cache Spill
2.1 When memory is low, DuckDB can spill data to a local disk cache instead of discarding it.
2.2 The cache is validated against the source to avoid stale data, so subsequent reads hit the disk instead of the network.
2.3 This reduces repeated network fetch times from seconds to milliseconds for large Parquet files.
3. Parallel Parquet Writes and Async Copy
3.1 DuckDB now supports writing partitioned and sorted Parquet files, enabling parallel output streams.
3.2 The async copy API is being extended to asyncify more stages of the write pipeline, though end‑to‑end async writes are not yet complete.
3.3 Using larger partitions and the partitioned write mode can give immediate performance gains.
4. Extension Mechanism for Custom Code
4.1 DuckDB’s C API allows building extensions in languages like C++, Rust, or embedding interpreters for Lua or JavaScript.
4.2 Python can be used via the map function or scalar UDFs that process batches of rows using Arrow.
4.3 This lets developers write high‑performance logic inside the database without leaving the process.
5. Tuning Async Threads
5.1 The async_threads configuration controls the size of the IO thread pool; increasing it can help when network latency is high.
5.2 On slower cloud providers like Azure Blob, raising async_threads can offset the latency difference.
5.3 Careful tuning balances memory usage and parallelism; too many threads may waste resources.
6. Cloud Provider Performance Variability
6.1 Benchmarks show that S3, Azure Blob, and GCS have similar performance, with Azure slightly slower on average.
6.2 The async I/O model mitigates differences by saturating available bandwidth, but tuning may still be needed.
6.3 Users should run their own benchmarks to validate performance in their specific environment.