Lightweight pipelining: parallelism · caching · persistence · the engine under scikit-learn · verified against joblib 1.5.x (2026)

joblib cheat sheet

joblib does three things really well: run embarrassingly-parallel loops with Parallel(delayed(...)), cache expensive function results to disk with Memory, and persist Python objects — especially big NumPy arrays — fast with dump/load. Zero required dependencies, a vendored loky process pool that survives crashes, and memory-mapping so worker processes share arrays without copying. It's the parallel/persistence engine inside scikit-learn. Targets joblib 1.5.x, Python 3.9+.

parallel backends & control caching (Memory) persistence (dump/load) gotchas & ecosystem gotcha most common

Verified 2026-08-31 against the official docs at joblib.readthedocs.io (joblib 1.5.3, released 2025-12-15; Python 3.9+). No mandatory dependencies (vendors loky & cloudpickle). Default parallel backend is loky (separate processes); use threading for I/O- or C-bound work that releases the GIL.

Outline

Parallel(delayed(f)(x) for x in xs) to parallelize; Memory to cache; dump/load to persist. Then pick the right backend and mind the pickling rules.

Parallel

  1. 1Install & first parallel
  2. 2Parallel patterns

Backends & control

  1. 3Backends & n_jobs
  2. 4Progress & return_as

Caching

  1. 5Memory caching
  2. 6Cache management

Persistence

  1. 7dump / load
  2. 8Compression & mmap

Gotchas & ecosystem

  1. 9Gotchas
  2. 10Ecosystem

Parallel

Turn a Python loop into parallel jobs with two names: Parallel and delayed.

1Install & first parallelParallel + delayed
2Parallel patternscommon shapes

Backends & Control

Choose processes vs threads, and watch progress or stream results.

3Backends & n_jobsprocesses vs threads
4Progress & return_asobserve & stream

Caching (Memory)

Memoize expensive functions to disk so you compute each result once.

5Memory cachingdisk memoization
6Cache managementcontrol it

Persistence (dump / load)

Fast, compressed serialization tuned for large NumPy arrays.

7dump / loadsave objects
8Compression & mmapsize & speed

Gotchas & Ecosystem

The pitfalls that bite, and where joblib sits.

9Gotchasavoid these
10Ecosystemwhere it fits

Worth memorizing

Parallel(n_jobs=)(delayed(f)(x) for x in xs)the core idiom
delayed(f)(x)NOT delayed(f(x)) — defer the call
n_jobs=-1all cores; -2 = all but one
backend loky vs threadingCPU (processes) vs I/O/GIL-free (threads)
parallel_config(...)override a library's backend/n_jobs
return_as="generator"stream results, bounded memory
Memory("./dir").cachedisk memoization across runs
reduce_size / clearbound / wipe the cache
dump / loadfast persistence for NumPy-heavy objects
compress= / mmap_mode="r"smaller files / zero-copy load
load = unpicklenever load untrusted files
coarse tasks + picklable fnsavoid overhead & pickle errors