/performance:optimize-performance [pipeline-name] [symptom]from performance
Diagnoses and resolves dlt pipeline performance issues including slow runs, high memory usage, and low throughput. Covers parallelism, workers, buffers, and file rotation tuning.
Ships in performance. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
dlt runs in three stages — extract → normalize → load — each with its own parallelism and memory knobs. Tuning the wrong stage wastes effort, so diagnose the bottleneck first (Step 1), fix that one stage (Step 2), then re-measure (Step 3).
Essential reading: https://dlthub.com/docs/reference/performance
Parse $ARGUMENTS:
pipeline-name (optional): the dlt pipeline. If omitted, infer from session context; if ambiguous, ask and stop.symptom (optional): what's wrong — "slow extract", "OOM during normalize", "load takes hours", etc.Source-specific knobs (DB backends/
chunk_size, REST async/concurrency, file format/readers) live in a separate pipeline toolkit — see Source-specific tuning for the toolkit to install. Apply those in addition to the stage levers here.Knobs below are shown as
config.toml; each has an env-var equivalent — see Config forms. Start from dlt's defaults and change one lever at a time.
Always measure before changing anything. Enable progress logging and read the per-stage timing:
# .dlt/config.toml
progress = "log" # or PROGRESS=log, or dlt.pipeline(..., progress="log")
Install psutil first (pip install psutil or uv add psutil) — then progress="log" adds a Memory usage: … MB (…%) | CPU usage: …% line per stage; without it dlt warns once (psutil dependency is not installed and memory stats will not be available) and omits that line. It's one interface across macOS/Windows/Linux, so the same profiling runs in dev and prod.
Read durations from pipeline.last_trace or via the calling pipeline toolkit's debug skill (trace + load packages; debug-pipeline in rest-api-pipeline, debug-sql-database-pipeline in sql-database-pipeline — use it only if that toolkit is installed, otherwise read last_trace directly). Benchmark on a real machine — shared or resource-constrained environments give unreliable numbers.
See where the rows and files went (dlt 1.32+; on older versions read pipeline.last_trace):
uv run dlthub local pipeline trace <pipeline_name> metrics # every step, by table
uv run dlthub local pipeline trace <pipeline_name> metrics --steps extract -v # one line per extracted file
It reads the last run trace: extract shows rows, files and sizes by resource and table; normalize by table (nested tables included); load shows files, sizes, job time and failed jobs by table (no rows). Use it to spot one table that dominates the run, a table that was never split into several files, or a load step dominated by a few slow jobs. Extract and normalize sizes are bytes before compression — the same unit file_max_bytes limits; load sizes are bytes on disk.
Tune on a representative subset, not the full dataset. For time tuning a slice (e.g. a few million of tens of millions of rows) reproduces the stage ratios and lever effects while iterating far faster. Size it in a band: big enough that fixed overhead doesn't dominate and that enough files/resources exist for parallelism levers to show (too small → a good lever looks useless; a tiny .add_limit(1) fails this floor and .add_limit() masks pagination), small enough to iterate. Reduce volume only once you've confirmed the subset is representative — it reproduces the full-run stage ratios and clears the floor (>1 file, >1 resource); if you can't confirm that, run the full dataset. Memory/OOM work and the final confirmation always run full volume.
Then route to the slowest stage:
| Bottleneck | Bound by | Go to |
|---|---|---|
| Extract slow | network / source I/O | Extract + Source-specific tuning |
| Normalize slow (CPU) | CPU | Normalize |
| Out of memory / killed, or disk full | RAM or disk | Out of memory |
| Load slow | destination I/O | Load |
Jump to the one section Step 1 flagged. Memory isn't a stage — it's a separate failure mode with its own section.
By default dlt extracts one resource at a time, one item at a time — N endpoints/tables are fetched sequentially. Parallelism overlaps those I/O waits, but only helps when multiple slow resources can overlap. Decide before adding workers:
pipeline.last_trace, or extract them individually). To probe one resource cheaply, cap it with .add_limit(max_items=N) or .add_limit(max_time=seconds) and time a few pages — don't extrapolate from a single item, and note .add_limit() masks pagination (re-verify before removing it; see adjust-endpoint/adjust-table). If one resource dominates, parallelizing the rest saves nothing — fix the slow one.workers ≈ number of slow resources to overlap. Excess workers idle or trip rate limits.| Lever | Default | Effect |
|---|---|---|
@dlt.resource(parallelized=True) | off | run the (sync) resource's generator in a worker thread, so resources overlap |
@dlt.defer on a per-item fn, then yield fn(item) | — | run per-item work (e.g. one HTTP request per item, inside a transformer) concurrently in the extract thread pool — the sync alternative to async |
async def resource / async @dlt.transformer | concurrent | many awaited items in flight on one event loop — no flag needed |
[extract] workers | 5 | thread-pool size for parallelized sync resources |
[extract] max_parallel_items | 20 | max in-flight items for async resources |
| yield pages, not rows | — | yield list(islice(it, 1000)) cuts per-item overhead; orthogonal to threading |
Group related resources into a @dlt.source (return (r1, r2, r3)) so dlt schedules them on a shared thread pool. Scopes for the knobs: global, per-source ([sources.<name>.extract]), per-resource.
Normalize runs a process pool; each worker gets a group of extract files. dlt sorts the files by name (a table's files stay together), cuts them into groups of similar size, and splits jsonl and parquet files separately. A worker never shares a file, so more workers only help if extract produced many files of similar size — one big file keeps one worker busy while the rest wait. Key rule: each stage's data_writer rotates the files it writes (= the next stage's input), so rotate extract output to parallelize normalize; rotate normalize output to parallelize load.
dlt checks this after extract and logs a warning when the files cannot keep the workers busy (it skips packages under 32 MiB): Normalize will give files to only N of M workers or Normalize will give N of M workers less than half the data of the busiest worker. The warning names the table to split, says whether to set or lower file_max_items / file_max_bytes (with the current values), and prints the trace metrics command that lists the extracted files.
Size the extract files from the data: aim for about 8–10 files per worker for the largest tables — [sources.data_writer] file_max_bytes ≈ extracted size ÷ (workers × 8), reading the size from trace metrics --steps extract. Prefer file_max_bytes to file_max_items when tables have different row widths (equal-size files split evenly). Small extract files do not add load jobs: each worker writes one normalized file per table.
| Lever | Default | Effect |
|---|---|---|
[normalize] workers | 1 (serial) | process pool; raise toward the CPU quota you actually have — read it from the cgroup (cpu.max on v2, cpu.cfs_quota_us ÷ cpu.cfs_period_us on v1), never from cpu_count(), which reports visible CPUs, not your allotment |
[normalize] start_method = "spawn" | — | recommended on Linux when resources use threads |
[data_writer] file_max_items / file_max_bytes | none | rotate stage outputs so normalize and load each get many files to split across workers — the lever that parallelizes both. Global [data_writer] rotates both stages' outputs at once; scope it to target one — [sources.data_writer] (extract output → parallelizes normalize), [normalize.data_writer] (normalize output → parallelizes load, see Load) |
[normalize.data_writer] disable_compression = true | off (gzip) | trade disk for CPU when CPU-bound |
Note: the extract writer is scoped under [sources.data_writer] (or global [data_writer]) — there is no [extract.data_writer] scope; dlt silently ignores that one (no error, no effect).
Running out of memory during normalize is a different problem with a different fix set → Out of memory.
A pipeline that runs out of resources on a constrained machine is short of RAM or of disk, and the fixes diverge. Don't guess; read how it died. Start from the table, then read the two exceptions under it — RAM does not always announce itself as a kill:
| Signal | RAM exhaustion | Disk exhaustion |
|---|---|---|
| How it dies | usually no Python traceback (two exceptions below). Exit 137 / SIGKILL or pod OOMKilled on k8s/Docker. On the dltHub platform, three signatures — all RAM: Runner killed (SIGKILL), exit code: 137 with an out-of-memory note (fast climb), Runner failed with exit code: 247 after a silent stall, or no kill at all (see below) | Python exception with traceback: OSError: [Errno 28] No space left on device |
| Killed by | the OS / k8s OOM-killer (RSS hit the cgroup/container limit) | dlt/Python writing intermediate, load-package, or staging files |
| Confirm mid-run | the progress="log" memory line (needs psutil — see Step 1); for the whole picture see Tracking memory below | df -h on the working volume and $DLT_DATA_DIR; du -sh ~/.dlt and the staging path |
A job can run out of RAM without dying — and that looks like a hang, not a crash. It sits with memory parked at the tier's limit, unchanging on every sample, emitting no progress lines at all, never killed, until the platform job's execute.timeout (its wall-clock limit) expires. Progress output stopped and memory at the ceiling is RAM exhaustion: cancel it and tune — don't wait for an exit code and don't raise the timeout. The same config can fail either way on different runs, so never key the diagnosis on the exit code alone.
With progress="log" on, tie a RAM spike to its stage: extract spiking = pulling the source into memory; normalize spiking = buffering items.
A traceback can still be a memory problem — read whose memory ran out. Once the destination has its own memory cap, its OOM arrives as a normal Python exception naming the limit (e.g. _duckdb.OutOfMemoryException: Out of Memory Error: could not allocate block of size …), wrapped by dlt as DatabaseTransientException, retried max_retry_count times, then LoadClientJobRetry and exit 1. That is the cap you set doing its job — an anonymous kill or stall converted into an attributable error. Fix it by raising the cap (keeping [load] workers × file size inside the box) or shrinking the files. A traceback that is neither Errno 28 nor a destination out-of-memory is a different bug → use the pipeline toolkit's debug skill (see Step 1).
The progress="log" line reports main-process RSS, which is complete for the default serial run but undercounts once [normalize] workers > 1 (the process pool runs in child processes).
It is a floor, not a peak — it is sampled at progress ticks, not continuously. A spike inside a stage (parsing a whole payload, materializing a dataframe) happens between two log lines and never appears. In practice it understates the true peak by 2–3×, and the gap is worst exactly where it matters — in a stage that allocates in bursts, such as load. Never conclude "memory is fine" from this line, and never size an instance down on the strength of it; only an OOM kill, or a peak you sample yourself (the runner exposes no cgroup peak counter — see below), gives you the real high-water mark.
The percentage is not your process's share — dlt prints
rssfor the current process but takes the percentage frompsutil.virtual_memory().percent, i.e. system-wide memory in use, so on a busy laptop an alarming percentage can sit next to a few-hundred-MB process. Never read it as "how close am I to the limit".On the dltHub runner it does tell you the tier, because
/proc/meminfothere is namespaced to the instance — so "system" is your instance,psutil.virtual_memory().totalis the tier's memory, andMB ÷ pctoff this line recovers it. Use either to confirm which tier a run actually got:dlthub deploy --show-manifestonly shows the size you declared, and prints norequireblock at all on the default tier.
How to see the whole picture depends on where you can reach:
docker stats / kubectl top pod / top (sorted by RSS) / cgroup memory.current vs memory.max. These measure the whole container, so they already include the normalize pool.dlthub job logs <name> (latest run), dlthub job runs logs <name> [run#] (a specific run), or -f to stream. The progress="log" memory lines show up here. Ref: https://dlthub.com/docs/hub/pipeline-operations/monitoringprogress="log" memory line lands in your logs; to capture the whole-tree peak with no external tooling, log the container's cgroup peak at the end of the run (cgroup v2: read /sys/fs/cgroup/memory.peak; v1: memory.max_usage_in_bytes) — it accounts for all processes in the container. On the dltHub runner neither peak file exists — it mounts cgroup v1 with only memory.limit_in_bytes and memory.usage_in_bytes, so there is no kernel high-water mark: sample memory.usage_in_bytes and RSS from a ~1 s thread and keep both maxima. They agree while dlt does its own Python work, then diverge once a memory-mapping destination (duckdb) loads, where RSS runs well above what the cgroup charges. RSS is the alarm; the cgroup figure is what gets you killed — a run peaking "over" the tier in RSS can still finish.OOMKilled in the pod status or orchestrator events confirms RAM was the cause even with no live metrics.| Lever | Default | Effect |
|---|---|---|
[data_writer] buffer_max_items | 5000 | items in RAM before flush; lower to cut memory (scope per stage: [sources.data_writer] for extract, [normalize.data_writer] for normalize; [data_writer] for both) |
| yield pages / stream input | — | stream the source (see Extract) so the extract side stays bounded — the load and destination still scale with data (see below) |
[data_writer] file_max_items / file_max_bytes | none | rotate files (global scope) so less is held in a single file at once |
Gotcha: buffer_max_items = 1 forces single-item writes and disables multithreading — don't. Cutting [extract] workers / [normalize] workers to fix memory usually just slows the run — those stages are bounded by the buffer levers above. [load] workers is the exception: load holds one whole file per thread, so its peak scales with workers × file size — see Load.
Cap the destination's own memory — dlt's buffers don't reach it. Streaming and file rotation bound dlt's in-flight memory, but the destination loads with its own memory and thread/connection settings — often sized to the machine's total RAM — in or beside the same process. When extract is already fully streamed but the run still OOMs on a constrained box, suspect the destination: dlt's buffer_max_items/rotation won't touch it. To fix, cap the destination itself, not dlt's workers:
Check the destination's own config for these knobs (they live in the destination, not in dlt). Capping destination memory and threads typically drops peak RSS several-fold versus running the destination at its RAM-sized defaults — often the single change that keeps a streamed load inside its limit.
Only once all the levers in this section are in place — buffers lowered, files rotated, destination capped, and the fresh-pipeline-per-object pattern below where it applies — is a genuinely undersized runner a possibility: see Step 4 (dltHub platform only).
Many-object loops — use a fresh pipeline per object. Reusing one pipeline object across many run() calls grows its in-memory state (schema deltas, load packages, cursor values) run-over-run, which can OOM a long job. Create a fresh pipeline per object and drop it when done:
for obj in objects:
pipe = dlt.pipeline(pipeline_name=f"load_{obj}", destination=..., dataset_name=...)
pipe.run(source_for(obj))
del pipe
Caveat: trades away cross-run convenience, and pipeline.default_schema.tables keeps every table ever loaded under a given pipeline name — track the object list explicitly.
Stop intermediate/staging files filling the volume: see Constrained disk / environment — point DLT_DATA_DIR at a bigger volume, stage to blob, set delete_completed_jobs, and keep compression on (don't disable_compression).
| Lever | Default | Effect |
|---|---|---|
[load] workers | 20 | thread pool, one file per thread; I/O-bound, safe to raise toward destination capacity — but bounded by memory: peak ≈ workers × file size (see below) |
Load runs one file per thread, so parallelism needs many normalize-output files: set [normalize.data_writer] file_max_items / file_max_bytes to rotate them (one file = one load job = no speedup). Smaller files also mean smaller transactions and less destination memory pressure.
Load-stage peak RAM ≈ [load] workers × file size, held in Python, plus whatever the destination allocates. This bites with insert_values (duckdb's default loader format), where each job is a file of SQL text. With wide rows both extremes overflow a small box: one un-rotated file is a single huge job, and rotating without touching workers just hands the default 20 threads a file each. Rotation is therefore a time lever and a memory lever in opposite directions — rotate for parallelism, then set workers so workers × file size fits the box.
Faster loader format (ADBC + parquet, dlt ≥ 1.19) — for slow loads into MSSQL, MySQL or Postgres. An ADBC driver lets dlt bulk-load parquet. ADBC is load-only; dlt has no ADBC source backend. Without a driver, dlt loads:
| source rows | Postgres | MSSQL | MySQL (sqlalchemy) |
|---|---|---|---|
Python objects (sqlalchemy backend, REST, …) | insert_values | insert_values | typed-jsonl |
Arrow (pyarrow / connectorx backend) | csv (COPY) | insert_values | parquet via batched inserts |
Local benchmark (dlt 1.32.0, 200k flat rows, Postgres and MySQL in Docker on the same machine):
insert_values; whole run ~1.5x.csv, but normalize disappears; whole run ~1.8x.| destination | enable | notes |
|---|---|---|
mssql | dbc install mssql → parquet is automatic | dlt converts the ODBC string (Encrypt=yes → true, no → disable); ingests per row-group to bound memory; no dictionary encoding |
sqlalchemy + mysql+pymysql://… | dbc install mysql; Python rows also need loader_file_format="parquet" | Arrow rows are already parquet; dlt maps ssl_* to tls-*; target database = dataset_name |
postgres | uv add adbc-driver-postgresql and loader_file_format="parquet" | no dbc needed |
sqlalchemy + sqlite | nothing — ADBC is disabled on purpose | the two SQLite builds corrupt the WAL -shm file; do not install the sqlite driver |
uv add adbc-driver-manager dbc # dbc is Columnar's ADBC driver installer
uv run dbc install mssql # or: uv run dbc install mysql
dbc installs into the venv (.venv/etc/adbc/drivers). Run it in every environment that loads: CI image, deploy build step, laptop.
pipeline = dlt.pipeline("p", destination="mssql", dataset_name="raw")
pipeline.run(source) # mssql picks parquet when the driver is found
pipeline.run(source, loader_file_format="parquet") # postgres; mysql for Python rows
Verify — the fallback is silent. Without a driver dlt drops ADBC; it warns only if you asked for parquet.
from dlt.destinations._adbc_jobs import has_adbc_driver # private dlt API
print(has_adbc_driver("mssql")) # (True, None) = found
pkg = pipeline.last_trace.last_load_info.load_packages[0]
print({j.job_file_info.file_format for j in pkg.jobs["completed_jobs"]})
Postgres and MSSQL data tables must show parquet. MySQL shows parquet even without the driver, so check has_adbc_driver("mysql"): (True, "…missing required option uri") also means found. dlt's own tables (_dlt_loads) always show insert_values. If not found, check for disable_adbc_detection = true in config.toml. The workers × file size rule above applies to parquet files too.
Other destinations — loader formats to test. The defaults below apply to Python-object rows. With an Arrow backend, dlt already writes parquet where the destination supports it. Treat any other format as an experiment: set loader_file_format= on pipeline.run and compare load time in last_trace. Re-test after you change file_max_items or [load] workers. Check your dlt version with dlt.destinations.<name>().capabilities().
| destination | default | also | notes |
|---|---|---|---|
| BigQuery | jsonl | parquet | stage via GCS for bulk; no Avro loader |
| Snowflake | jsonl | parquet, csv | compare csv (flat rows) with parquet (types) |
| Databricks | parquet | jsonl | via staging |
| ClickHouse | jsonl | parquet | |
| Redshift | insert_values | jsonl, parquet via staging | large loads need a staging bucket |
| Postgres | insert_values | csv, parquet | parquet via ADBC |
| MSSQL | insert_values | parquet | parquet via ADBC |
MySQL (sqlalchemy) | typed-jsonl | parquet | parquet via ADBC |
| DuckDB | insert_values | parquet, jsonl | Arrow sources load as parquet |
The biggest extraction wins are source-specific and live in the pipeline toolkit for your source — not in this toolkit. Pick the row for your source. If you arrived here from that toolkit it is already installed; otherwise install it first, then run its optimize skill:
uv run dlthub --non-interactive ai toolkit install <toolkit>
| Source | Install toolkit | Then run skill |
|---|---|---|
| REST / HTTP API | rest-api-pipeline | optimize-rest-api-performance |
| SQL database | sql-database-pipeline | optimize-sql-performance |
| Files (S3 / GCS / Azure / SFTP / local) | filesystem-pipeline | optimize-filesystem-performance |
Apply source-specific tuning in addition to the stage levers above. These skills live in other toolkits, so always install the toolkit before invoking the skill — never assume it is present.
Re-run with progress="log" and compare per-stage durations against Step 1, plus the peak Memory usage line it logs (last_trace has timings, not RAM). Compare file counts and sizes per table with trace metrics too — a rotation lever that did not change the number of extract files did not take effect (check the config scope).
Change one lever at a time so you can attribute the effect, and use the pipeline toolkit's debug skill to confirm no new failures (timeouts, type errors) surfaced under higher concurrency. If a lever regresses — slower, higher peak memory, or a new failure — roll it back to its previous value before trying the next; changing one at a time is what makes this a clean revert.
Iterate on one stage — skip the full run(). dlt exposes each stage as its own method (pipeline.extract(source), pipeline.normalize(), pipeline.load()), and each consumes the previous stage's packages. So when tuning a lever, re-run from the changed stage's input forward, up to the stage you're timing — not the whole pipeline:
| Lever | Re-run |
|---|---|
| extract parallelism / page size | extract() |
[normalize] workers, extract-output rotation | extract() → normalize() |
[load] workers, normalize-output rotation (parallelizes load) | extract() → normalize() → load() |
Two exceptions — use a full run(): memory/OOM work (peak RSS is cross-stage and the destination loads with its own memory), and the final confirmation run that re-diagnoses whether the bottleneck moved.
Stop or repeat — check in, don't loop autonomously. Report the before/after to the user, then:
Applies only to pipelines on the dltHub platform, and only once Steps 1–3 are done and re-measured. A bigger runner is not a tuning lever — it is a recurring cost charged against your organization's run-time budget by a multiplier, every run, forever.
Never change it without the user's explicit permission. This is a spending decision, not a tuning decision: diagnose and propose, never edit require, deploy a size change, or raise execute={"timeout": ...} on your own initiative — not when the job is OOM-killed, not when it is timing out, not when the user asked you to "just make it work".
Two facts that save a wasted trip: disk is the same on every tier, so scaling up never fixes Errno 28; and each step doubles the charge, so it must roughly halve wall-clock to break even.
When Steps 1–3 are genuinely exhausted and the runner itself is the measured ceiling, read instance-sizing.md — gates, anti-signals, the budget-math question to ask, and how to apply the change. Do not read it earlier; "raise the instance size" is not an option until the gates there pass.
Reference: https://dlthub.com/docs/hub/pipeline-operations/job-configuration#instance-size
@dlt.defer → thread pool (sync alternative to async). Decorate a per-item function and yield its calls so dlt runs them concurrently in the extract thread pool — ideal for per-item I/O in a transformer (e.g. one request per parent) without rewriting to async. Sized by [extract] workers / max_parallel_items, same as parallelized=True.@dlt.transformer
def details(items):
@dlt.defer # runs in the extract thread pool
def fetch(item):
return requests.get(item["url"]).json()
for item in items:
yield fetch(item) # calls run concurrently
See the transformers example: https://dlthub.com/docs/examples/transformers
Every knob can be set in .dlt/config.toml under a section, or as an env var by upper-casing and joining the path with double underscores:
[extract] workers = 5 ⇄ EXTRACT__WORKERS=5[data_writer] file_max_items = 100000 ⇄ DATA_WRITER__FILE_MAX_ITEMS=100000DLT_DATA_DIR=/path/to/large/or/mounted/volume — offload load packages off the working disk.dlt.pipeline(..., staging=dlt.destinations.filesystem(bucket_url="s3://.../stage")). Only worth it when disk space is actually the problem.delete_completed_jobs — reclaim disk after each load.DLT_USE_JSON=simplejson — only if orjson (the fast default) causes issues.source().decompose(strategy="scc") — returns sub-sources with independent components; run serially or in parallel.asyncio.gather): give each pipeline a unique name and instantiate generators inside the worker thread. Never run two same-named pipelines in parallel on one machine (state conflicts). See the performance doc above.deploy-workspace).uv run dlthub --non-interactive ai toolkit install dlthub-platform).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub dlt-hub/dlthub-ai-harness --plugin performanceOther plugins' skills for the same job