Optimize Performance¶
This guide covers the main performance levers in fsspeckit: filesystem caching, parallel file I/O, parallel custom processing, and type optimization.
For exact signatures, see fsspeckit.core and fsspeckit.common.
Filesystem caching¶
Caching stores remote data locally so repeated reads avoid round trips. Enable
it with cached=True, and point cache_storage at fast local storage when
possible:
- Cache remote filesystems; local filesystems gain nothing from it.
- Use fast local storage (NVMe/SSD) for
cache_storageon read-heavy workloads. - Leave caching off for write-heavy remote paths.
- Clear a cache with
fs.clear_cache().
For the cache configuration parameters, see fsspeckit.core.
Parallel file I/O¶
The extended read methods accept use_threads to read multiple files
concurrently:
use_threads helps when reading many files; for a single file it has little
effect. Set use_threads=False when debugging or when parallelism causes
contention.
For very large sets of files, read in batches with batch_size so only one
batch is in memory at a time:
Parallel custom processing¶
run_parallel() runs a function over one or more iterables concurrently using
joblib. Iterable arguments are zipped together; non-iterable arguments are
passed fixed to every call. It shows a progress bar by default.
n_jobs=-1 (the default) uses all cores for the threading backend. Choose
backend="threading" for I/O-bound work and backend="loky" or
"multiprocessing" for CPU-bound work. joblib ships as a core dependency.
Batched dataset processing¶
To process a parquet dataset in memory-bounded chunks, iterate a PyArrow
dataset with process_in_chunks, which yields pa.Table slices and enforces
a memory ceiling via a MemoryMonitor:
This requires the datasets extra. See the
extras matrix, and
Memory-Constrained Environments for
configuring the monitor.
Type optimization¶
Optimizing column dtypes reduces memory and speeds up downstream processing.
The extended read methods accept opt_dtypes=True to optimize on read:
For explicit control over schema and types, use the schema utilities in
fsspeckit.datasets. These require the datasets extra (or polars for the
Polars variants):
For Polars type optimization, use opt_dtype_pl (requires the polars extra).
See the Public API Inventory for the
full symbol list.
Dataset maintenance¶
Compacting small files into fewer larger ones improves read performance. Use the coordinator-backed filesystem façade; it returns a typed result and exposes an explicit plan when review is needed.
See Coordinator-backed Maintenance for the planning workflow and guarantee levels, and Maintain Parquet Datasets for the full task guide including deduplication, repartitioning, and optimization.
Related documentation¶
- Memory-Constrained Environments - memory monitoring and streaming merge.
- Dataset Handlers - maintenance and backend options.
- Work with Filesystems - caching and extended I/O.