Jump to content

Project Tungsten

From Open Lakehouse Wiki
Project Tungsten
Also known as Tungsten, Tungsten execution engine
Field Query execution performance
Introduced Spark 1.4.0 (first pieces); phase 1 completed in Spark 1.5.0
Key parts Explicit (on-heap or off-heap) memory management, UnsafeRow binary row format, cache-aware sorting and hashing, code generation including whole-stage code generation
Open source implementations Apache Spark
Related Catalyst optimizer, Whole-stage code generation, Executor, Shuffle, Native execution engine (Spark)
Last verified 22 November 2026 against SPARK-7075, SPARK-7081, SPARK-9697, SPARK-10708 and SPARK-12795, the Spark 1.4.0, 1.5.0 and 2.0.0 release notes, the v1.5.0, v1.6.0, v2.0.0 and v4.3.0 tags of apache/spark (SQLConf, SetCommand, SparkEnv, ShuffleManager, MemoryManager, TaskMemoryManager, UnsafeRow, WholeStageCodegenExec, docs/configuration.md) and EXPLAIN output from a Spark 4.3 build.
Status: Active. Project Tungsten is not deprecated in any Spark release. It was a performance initiative, not a feature with an on/off switch; its code is the default execution path in Spark 4.3.0. Only its old configuration flag, spark.sql.tungsten.enabled, was deprecated (Spark 1.6.0) and later dropped.[1]

Project Tungsten is the name of an Apache Spark engineering initiative, started in 2015, to make Spark's execution more efficient in CPU and memory by managing memory explicitly, storing rows in a compact binary format, using CPU caches better and generating code at run time.[2] Tungsten is not a separate engine or a module that can be installed or turned off: its results (for example the UnsafeRow format, Tungsten-managed memory pages and whole-stage code generation) are part of how Spark SQL and DataFrame queries run in every current release. The name survives mostly in source code, configuration aliases and older documentation.

What the name referred to

The umbrella ticket SPARK-7075, "Project Tungsten (Spark 1.5 Phase 1)", states the premise: most Spark workloads observed by its authors were bottlenecked by CPU and memory rather than by I/O or network. It names three areas of work:[2][3]

  • Memory management and binary processing. Keep data in a binary format instead of as Java objects, to reduce garbage collection overhead and memory use; account for memory in bytes; and let operators that know the data types work directly on the binary data without serialization.
  • Cache-aware computation. Algorithms and data structures, such as sorting and hashing, laid out to make better use of CPU caches.
  • Code generation. Generate code at run time for expression evaluation and serialization, to use modern compilers and CPUs better.

The work arrived over several releases. The Spark 1.4.0 release notes list SPARK-7081, a faster sort-based shuffle path, as "Initial performance improvements in project Tungsten".[4][5] Phase 1 (SPARK-7075) has fix version 1.5.0, and the 1.5.0 release notes say that optimized execution with manually managed memory (Tungsten) was now on by default, together with code generation for expression evaluation.[2][6] A phase 2 umbrella followed (SPARK-9697).[7] Whole-stage code generation (SPARK-12795) shipped in Spark 2.0.0, and a 2016 Databricks post by Spark developers presented it as the core of a "second generation Tungsten engine".[8][9] The Spark 2.0.0 release notes describe whole-stage code generation without using the Tungsten name.[10]

What remains in Spark 4

Project Tungsten has no deprecation or removal in any Spark release. Its pieces are ordinary parts of the engine:

  • Tungsten memory. Spark's memory manager still allocates "Tungsten" memory pages for sorting, hashing and shuffle, on the JVM heap by default or off-heap through sun.misc.Unsafe when spark.memory.offHeap.enabled is true (default false, available since 1.6.0).[1][11][12] See Spark memory management.
  • The UnsafeRow format. Spark SQL's internal row format is backed by raw memory instead of Java objects: a null-tracking bit set, one 8-byte word per field, and a variable-length region for strings and other variable-length values.[13]
  • Whole-stage code generation. Enabled by default through the internal setting spark.sql.codegen.wholeStage (default true, since 2.0.0). In EXPLAIN output, an operator compiled into a generated stage is prefixed with *(n), where n is the code generation stage ID.[14][15] See Whole-stage code generation.
  • The tungsten-sort shuffle alias. Spark 1.5.0 mapped spark.shuffle.manager=tungsten-sort to a separate UnsafeShuffleManager. SPARK-10708 merged it into the sort shuffle manager in 1.6.0, and since then tungsten-sort is an alias for SortShuffleManager, as it still is in 4.3.0.[16][17][18]

The spark.sql.tungsten.enabled flag

The one Tungsten item that was deprecated is a configuration flag. In Spark 1.5.0, spark.sql.tungsten.enabled (default true) switched the Tungsten execution backend and code generation on or off.[6][19] Spark 1.6.0 removed the option to turn off the unsafe (Tungsten) and code generation paths (SPARK-11644)[20] and moved the flag to a list of deprecated keys: setting it logged a warning that the property "is deprecated and will be ignored. Tungsten will continue to be used."[21] By Spark 2.0.0 the SET command no longer has any special handling for it.[22] There has been no way to turn Tungsten off as a whole since 1.6.0.

Example

This PySpark query runs a filter and an aggregation. After the query has run, explain() shows the final adaptive plan, where the *(1) prefix marks the three operators that were compiled together into one generated function.

df = spark.range(1000).filter("id % 2 = 0").selectExpr("sum(id)")
df.collect()
df.explain()

Part of the output from a Spark 4.3 build:

   ResultQueryStage 0
   +- *(1) HashAggregate(keys=[], functions=[sum(id#0L)])
      +- *(1) Filter ((id#0L % 2) = 0)
         +- *(1) Range (0, 1000, step=1, splits=1)

What Tungsten is not

  • Not the optimizer. The Catalyst optimizer decides what plan to run; Tungsten work concerns how the chosen physical operators use memory and CPU. The MLlib guide, for example, lists "Tungsten and Catalyst optimizations" as benefits of DataFrames.[23]
  • Not a native engine. Tungsten code runs in the JVM and generates Java code. Native execution engines for Spark, such as Apache Gluten (with Velox) and Apache DataFusion Comet, replace JVM operators with native code; Photon is a proprietary Databricks engine. See Native execution engine (Spark).
  • Not available to RDD code. The binary row format and generated code apply to DataFrame, Dataset and SQL operators, which know the data types. Programs that use the RDD API with arbitrary JVM objects do not get these benefits.[2]

See also

References

  1. ↑ 1.0 1.1 MemoryManager.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  2. ↑ 2.0 2.1 2.2 2.3 SPARK-7075: Project Tungsten (Spark 1.5 Phase 1). Apache Software Foundation JIRA.Retrieved 2026-11-22.
  3. ↑ Project Tungsten: Bringing Apache Spark Closer to Bare Metal. Databricks, 2015-04-28.Retrieved 2026-11-22.
  4. ↑ Spark Release 1.4.0. Apache Software Foundation.Retrieved 2026-11-22.
  5. ↑ SPARK-7081: Faster sort-based shuffle path using binary processing cache-aware sort. Apache Software Foundation JIRA.Retrieved 2026-11-22.
  6. ↑ 6.0 6.1 Spark Release 1.5.0. Apache Software Foundation.Retrieved 2026-11-22.
  7. ↑ SPARK-9697: Project Tungsten (Phase 2). Apache Software Foundation JIRA.Retrieved 2026-11-22.
  8. ↑ SPARK-12795: Whole stage codegen. Apache Software Foundation JIRA.Retrieved 2026-11-22.
  9. ↑ Apache Spark as a Compiler: Joining a Billion Rows per Second on a Laptop. Databricks, 2016-05-23.Retrieved 2026-11-22.
  10. ↑ Spark Release 2.0.0. Apache Software Foundation.Retrieved 2026-11-22.
  11. ↑ TaskMemoryManager.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  12. ↑ Spark Configuration (docs/configuration.md at v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  13. ↑ UnsafeRow.java (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  14. ↑ SQLConf.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  15. ↑ WholeStageCodegenExec.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  16. ↑ SparkEnv.scala (v1.5.0). Apache Software Foundation.Retrieved 2026-11-22.
  17. ↑ SPARK-10708: Consolidate SortShuffleManager and UnsafeShuffleManager. Apache Software Foundation JIRA.Retrieved 2026-11-22.
  18. ↑ ShuffleManager.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
  19. ↑ SQLConf.scala (v1.5.0). Apache Software Foundation.Retrieved 2026-11-22.
  20. ↑ SPARK-11644: Remove the option to turn off unsafe and codegen. Apache Software Foundation JIRA.Retrieved 2026-11-22.
  21. ↑ commands.scala (v1.6.0). Apache Software Foundation.Retrieved 2026-11-22.
  22. ↑ SetCommand.scala (v2.0.0). Apache Software Foundation.Retrieved 2026-11-22.
  23. ↑ Machine Learning Library (MLlib) Guide (docs/ml-guide.md at v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.