<< All versions
Skill v1.0.0
currentLLM-judged scan90/100trraveendra/the-ai-codex/performance-tuning
──Details
PublishedOctober 21, 2026 at 10:27 AM
Content Hashsha256:76c180a6ab37e5ed...
Git SHAeffa5f9d615b
──Files
Files (1 file, 2.7 KB)
SKILL.md2.7 KBactive
SKILL.md · 119 lines · 2.7 KB
version: "1.0.0" name: performance-tuning description: Optimize Spark and Delta Lake performance through partitioning, caching, join strategies, and query tuning.
Performance Tuning Skill
When to Use
Use when queries are slow, jobs timeout, or storage costs are high.
Delta Lake Optimization
OPTIMIZE + ZORDER
sql
-- Compact small files and co-locate dataOPTIMIZE main.gold.salesZORDER BY (customer_id, date);-- Incremental optimize (only recent partitions)OPTIMIZE main.gold.salesWHERE date >= current_date() - INTERVAL 7 DAY;
Liquid Clustering (Recommended for new tables)
sql
-- Create table with liquid clusteringCREATE TABLE main.gold.eventsCLUSTER BY (event_date, user_id)AS SELECT * FROM main.silver.events;-- Trigger clusteringOPTIMIZE main.gold.events;
Statistics
sql
ANALYZE TABLE main.gold.sales COMPUTE STATISTICS FOR ALL COLUMNS;
Partitioning Strategy
sql
-- Partition by date for time-series dataCREATE TABLE main.gold.events (event_id STRING, event_date DATE, payload STRING) USING DELTAPARTITIONED BY (event_date);
Rules of thumb:
- Partition when table > 1 TB
- Each partition should have > 1 GB of data
- Max 10,000 partitions
- Use date columns (not high-cardinality)
Join Optimization
python
# Broadcast small tables (< 100 MB)from pyspark.sql.functions import broadcastresult = large_df.join(broadcast(small_df), "key")# Check join strategy in explain planresult.explain(True)
sql
-- SQL broadcast hintSELECT /*+ BROADCAST(dim) */f.*, dim.nameFROM main.gold.facts fJOIN main.gold.dimensions dim ON f.dim_id = dim.id;
Caching
python
# Cache frequently accessed DataFramesdf.cache()df.count() # trigger cache materialization# Unpersist when donedf.unpersist()
sql
-- SQL cachingCACHE TABLE main.gold.dim_products;UNCACHE TABLE main.gold.dim_products;
Spark Configuration
python
# Adaptive Query Execution (enabled by default)spark.conf.set("spark.sql.adaptive.enabled", "true")spark.conf.set("spark.sql.adaptive.coalescePartitions.enabled", "true")# Shuffle partitions (default 200, tune based on data size)spark.conf.set("spark.sql.shuffle.partitions", "auto")
Diagnostics
sql
-- Check table file sizesDESCRIBE DETAIL main.gold.sales;-- Check table historyDESCRIBE HISTORY main.gold.sales;-- Query profileEXPLAIN EXTENDED SELECT * FROM main.gold.sales WHERE date = current_date();
Best Practices
- Use Liquid Clustering over manual partitioning for new tables
- Run OPTIMIZE on a schedule (daily for active tables)
- Use ZORDER on frequently filtered columns
- Enable Photon for compute acceleration
- Avoid SELECT * — project only needed columns
- Filter early, aggregate late