
analyzing-compiler-graphs
by antonykamp
A Claude plugin for analyzing and optimizing Truffle performance
SKILL.md
name: analyzing-compiler-graphs description: Dumps and analyzes Graal IR compiler graphs showing optimization decisions. Use BGV format with bgv2json/seafoam to inspect escape analysis, boxing removal, inlining decisions, and call node types. Reveals what compiler actually optimized vs intended. Use as last resort after basic profiling when root cause remains unclear.
Analyzing Compiler Graphs
Deep-dive tool for understanding Graal compiler optimization decisions at the IR level. Dumps BGV files and analyzes them to reveal exactly what the compiler optimized.
When to Use This Skill
Use AFTER simpler profiling tools when:
- Other tools show problems but don't reveal root cause
- Need to understand WHY optimization fails
- Investigating allocation elimination issues
- Debugging polymorphism and specialization
Prerequisites:
- ✅ CPU profiling identified hot methods
- ✅ Performance warnings revealed optimization barriers
- ✅ Compilation/inlining traces showed issues
- ✅ bgv2json or Seafoam installed
Quick Start
1. Dump Compiler Graphs
# Basic dump for Truffle compilations
<launcher> --vm.Djdk.graal.Dump=Truffle:1 \
--vm.Djdk.graal.PrintGraph=File \
--vm.Djdk.graal.DumpPath=compiler_graphs \
<program>
# Focused dump for specific method (recommended)
<launcher> --vm.Djdk.graal.Dump=Truffle:1 \
--vm.Djdk.graal.MethodFilter='*hotFunction*' \
--vm.Djdk.graal.DumpPath=compiler_graphs \
--engine.CompileOnly='*hotFunction*' \
<program>
2. Analyze with Seafoam
# Get help
seafoam help
# Describe graph characteristics
seafoam --json compiler_graphs/*.bgv.gz:2 describe
# Render to SVG
seafoam compiler_graphs/*.bgv.gz:2 render > graph.svg
3. Convert to JSON for Custom Analysis
bgv2json compiler_graphs/*.bgv > graphs.json
See DUMPING.md for detailed dump options. See QUERIES.md for jq analysis queries.
⚠️ REQUIRED: Fermi Verification (Every Tool Invocation)
Before dumping graphs:
- Pre-calculate: Expected # of BGV files (1 per compiled function, typically 5-20)
- Smoke test: Dump trivial program first → Verify BGV files generated
After dumping:
- Validate: BGV file count within expectation? YES / NO
- If NO: STOP - Check MethodFilter, verify functions compiled
- List BGV files:
ls -lh compiler_graphs/*.bgv
After analyzing graphs:
- Validate: Node counts reasonable? YES / NO
- If NO: STOP - May have wrong phase or too broad filter
- Save analysis:
tool-outputs/compiler-graph-analysis-[function].txt
Gate: All boxes checked? → Proceed to interpretation
Key Phases to Analyze
| Phase | Purpose | What to Check |
|---|---|---|
| After TruffleTier | Most important | Direct calls, constant nodes, no VirtualFrame refs |
| After PartialEscape | Allocation elimination | Zero allocation nodes if EA worked |
| Final | Generic Graal optimizations | Overall node reduction |
Quick Problem Detection
Check for Indirect Calls (Performance Problem!)
seafoam --json file.bgv.gz:2 describe | \
jq '.node_counts | to_entries | .[] | select(.key | contains("Call"))'
Good: OptimizedDirectCallNode
Bad: OptimizedIndirectCallNode, InvokeNode
Check for Failed Escape Analysis
cat graphs.json | jq 'select(.name | contains("After PartialEscape")) |
.nodes[] | select(.props.label | test("Alloc|New"))'
Good: Empty output
Bad: CommitAllocationNode, NewInstanceNode present
Check for Boxing
seafoam --json file.bgv.gz:2 describe | \
jq '.node_counts | to_entries | .[] | select(.key | test("Box|Unbox"))'
Good: Empty output
Bad: BoxNode, UnboxNode present
Node Types Reference
Good Patterns (Optimized)
OptimizedDirectCallNode- Specialized calls ✅AddNode,MulNode,SubNode- Primitive arithmetic ✅ConstantNode- Constants from partial evaluation ✅
Bad Patterns (Need Fixes)
OptimizedIndirectCallNode- Need caching ⚠️InvokeNode- Unspecialized method calls ⚠️CommitAllocationNode,NewInstanceNode- Escape analysis failed ⚠️BoxNode,UnboxNode- Missing primitive specializations ⚠️DeoptimizeNodein hot paths - Unstable assumptions ⚠️
Common Problem Patterns
Problem 1: Indirect Calls
Fix: Add @Cached for CallTarget lookup
Problem 2: Failed Escape Analysis
Fix: Keep object lifetime strictly local
Problem 3: Boxing/Unboxing
Fix: Add primitive specializations
See PATTERNS.md for detailed fix examples.
Best Practices
- Always use MethodFilter - Avoid overwhelming output
- Start with Level 1 - Only use Level 2 when needed
- Focus on "After TruffleTier" - Most relevant for language developers
- Compress BGV files -
gzip compiler_graphs/*.bgv - Correlate with other tools - Use with TraceCompilation, TracePerformanceWarnings
Related Skills
profiling-with-cpu-sampler- Identify hot functions FIRSTdetecting-performance-warnings- Find optimization barrierstracing-compilation-events- See compilation eventstracing-inlining-decisions- Check inliningdetecting-deoptimizations- Find instabilitiesfetching-truffle-documentation- API reference
Detailed Documentation
- DUMPING.md - Dump options and commands
- QUERIES.md - jq analysis queries
- PATTERNS.md - Problem patterns and fixes
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です