The three magic words for performance
Three mechanisms that turn a naive pipeline into a fast one — AUTOTUNE, caching, prefetching. Use all three by default.
AUTOTUNE (tf.data.AUTOTUNE): instead of hardcoding num_parallel_calls=4, let TF measure throughput at runtime and tune parallelism dynamically. Almost always better than any fixed value.
Caching (.cache()): saves the output of the pipeline at that point. First epoch runs the preprocessing and stores results; subsequent epochs read from cache. Use .cache() in memory if data fits, .cache("/tmp/path") for disk caching of larger sets.
Prefetching (.prefetch(AUTOTUNE)): overlaps CPU data preparation with GPU model computation. Always the LAST step in the pipeline. Adding it to a pipeline that didn't have it often gives 20–50% speedup with zero code complexity — it's free performance.