Optimizing Spark performance

By Hatnest · Reviewed by Saurav Raj Joshi · Updated Nov 30, 2026

Spark performance has three layers: how quickly a session starts, how well the compute matches the job, and how the code and data behave once running. Fabric gives you a lever in each layer.

Layer 1: session start-up

  • Starter pools are prewarmed clusters. With no extra libraries or custom Spark properties, a session typically starts in 5 to 10 seconds. They use Medium nodes only. Choosing another node size, using private links or managed virtual networks, or running when a region's starter capacity is used up falls back to on-demand startup, which can take 2 to 5 minutes.
  • Libraries slow start-up. Libraries and custom properties in an environment are applied when the session starts. Installing them adds from about half a minute to several minutes depending on the publishing mode. Keep environments lean, and for predictable fast starts, such as scheduled jobs, use a custom live pool that keeps clusters warm.
  • High concurrency mode lets compatible notebooks or pipeline notebook activities share one running Spark session, each isolated in its own REPL. Later workloads start much faster and cost less. Sharing needs the same user, the same default lakehouse and the same Spark compute settings, otherwise a separate session starts. In a pipeline that runs notebooks in a ForEach, enable it and use session tags so the notebooks share a session.

Layer 2: match compute to the job

  • Custom Spark pools let you choose node size and autoscale limits. Autoscale and dynamic allocation add and remove executors with demand, so a large range avoids paying for idle nodes while still handling peaks.
  • Resource profiles apply tested bundles of Spark and Delta settings through one property, spark.fabric.resourceProfile. New workspaces use writeHeavy, which favors ingestion with V-order off. readHeavyForPBI turns V-order on for Power BI and Direct Lake reads, readHeavyForSpark suits frequent Spark reads, and custom is yours to define. Pick the profile that matches the dominant workload.
  • Native execution engine. It runs supported operators on a vectorized C++ path instead of the JVM, with no code changes, on runtime 1.3 and later. It reads Parquet and Delta natively and helps compute-heavy transformations and aggregations most. Unsupported features fall back to normal Spark, which removes the gain, so check what your queries use. Enable it in the environment (Spark compute, Acceleration) to apply it to every notebook and job that uses it.
  • Autotune (preview, off by default) adjusts three query settings per query: the number of shuffle partitions (default 200), the broadcast join threshold (default 10 MB) and the maximum bytes per input partition (default 128 MB). It learns from past runs, works best for repeated queries longer than 15 seconds, and needs roughly 20 to 25 runs to settle. It is available only on runtime 1.2, and it does not run with high concurrency mode or private endpoints. Enable it with spark.ms.autotune.enabled=true.
  • Use a recent runtime. Newer runtimes bring engine improvements and support the native engine.

Layer 3: code and data

Most slow jobs are slow because of shuffles, skew or too much data read.

  • Read less. Select needed columns, filter early and rely on file skipping from clustering or partitioning. Keep the table's files healthy; see the lakehouse optimization article.
  • Joins. Broadcast a small table to avoid shuffling the large one. Keep broadcast off for large tables or you risk memory failures. Adaptive query execution is on by default and can handle skewed joins when spark.sql.adaptive.skewJoin.enabled is true.
  • Partition sizes. Aim for about 128 to 256 MB per partition. As a start, divide estimated data size by 200 MB to choose the repartition count. Check input sizes per task in the Stages tab of the Spark UI.
  • Skew. If a few tasks run far longer than the rest in the Stages tab, the key is skewed. Remedies are skew-join handling or repartitioning on a better key.
  • Caching. Cache only data you reuse, and unpersist it afterward.
  • Be careful with Python UDFs. They are a known trigger of memory pressure, so prefer built-in functions where one exists.
df = (spark.read.table("sales")
        .select("order_id", "customer_id", "amount")
        .where("order_date >= '2026-01-01'"))
dim = spark.read.table("customers")
out = df.join(dim.hint("broadcast"), "customer_id")   # small dimension is broadcast
out.repartition(200).write.mode("overwrite").saveAsTable("sales_enriched")

Settings in the right place

Resource settings such as executor and driver memory are read at session start. Put them in a %%configure cell at the top of the notebook or in the environment, since spark.conf.set() later does not change them.

Diagnose first

Use the Spark UI and the history server's diagnosis tab for skew, spill and executor usage, and the Spark advisor in notebooks for hints. Change one thing at a time.

For the exam

  • Starter pools start in seconds only with Medium nodes and no libraries; custom live pools give predictable starts.
  • High concurrency mode shares a session between notebooks with the same user, lakehouse and compute settings.
  • Resource profiles: writeHeavy is the default; readHeavyForPBI enables V-order.
  • The native execution engine speeds up compute-heavy Parquet and Delta queries without code changes.
  • Fix skew with adaptive execution, better partitioning and broadcast joins for small tables.

Sources