# Whole-stage code generation

Glossary, read 10 Nov 2026

**The short answer.** Whole-stage code generation fuses a chain of Spark SQL operators into one generated Java function, so rows pass between operators in CPU registers instead of through virtual next() calls. It arrived in Spark 2.0 as part of the second-generation Tungsten engine, described in a May 2016 Databricks engineering post.

Before it, Spark 1.x used the Volcano iterator model, where each operator returned one row per call. Fusing the operators removed most of that overhead for filters, aggregates and hash joins.

Native engines such as Velox take the idea further by processing batches of columns with vectorized code. See [Tungsten](/glossary/tungsten/) and [vectorized execution](/glossary/vectorized-execution/).

## A sourced example

The 2016 post measured single-thread cost per row in Spark 1.6 against 2.0: filter 15 ns to 1.1 ns, sum without group 14 ns to 0.9 ns, Parquet decoding of one int column 120 ns to 13 ns.

## Sources

- Databricks blog: Apache Spark as a Compiler (May 23, 2016): https://www.databricks.com/blog/2016/05/23/apache-spark-as-a-compiler-joining-a-billion-rows-per-second-on-a-laptop.html (read 10 Nov 2026)

Last reviewed 10 Nov 2026. Canonical: https://sparkaccelerationcompare.com/glossary/whole-stage-code-generation/
