AgentSkillsCN

detecting-deoptimizations

追踪反优化事件,即在执行过程中从已编译代码回退至解释器的情况。借助该工具,可有效检测反优化循环、不稳定假设以及类型不稳定性等问题。在稳态下,零次转移应是理想目标;若转移次数过多,则往往预示着严重的性能瓶颈。对于诊断编译过程中的稳定性问题而言,此项分析至关重要。

SKILL.md
--- frontmatter
name: detecting-deoptimizations
description: Traces deoptimization events where execution falls back from compiled code to interpreter. Use to detect deoptimization loops, unstable assumptions, and type instability. Zero transfers in steady-state is the goal. Many transfers indicate severe performance problems. Critical for diagnosing compilation instability.

Detecting Deoptimizations

Traces every deoptimization event where execution falls back from compiled code to interpreter. Critical for finding the most severe performance problems.

Why Deoptimizations Are Catastrophic

  • Single transfer cost: Hundreds of nanoseconds (vs ~5ns for normal call)
  • Deoptimization loops: 10-100x slower than pure interpreter!
  • Wasted compilation: Compile → deoptimize → recompile → deoptimize = disaster

Goal: Zero transfers in steady-state execution!

When to Use This Skill

  • Investigate poor performance despite successful compilation
  • Profile shows methods in interpreted mode
  • Debug why compiled code keeps falling back
  • Verify benchmarks have properly warmed up

Quick Start

bash
# Basic deoptimization trace
<launcher> --experimental-options \
  --engine.TraceTransferToInterpreter <program>

# Combined with compilation trace (HIGHLY RECOMMENDED)
<launcher> --experimental-options \
  --engine.TraceTransferToInterpreter \
  --engine.TraceCompilation \
  <program> 2>&1 | tee transfers.log

# Focus on specific function
<launcher> --experimental-options \
  --engine.TraceTransferToInterpreter \
  --engine.CompileOnly=functionName \
  <program>

⚠️ REQUIRED: Fermi Verification (Every Tool Invocation)

Before running:

  • Pre-calculate: Expected transfers (0-50 during warmup, 0 in steady-state)
  • Smoke test: <launcher> --experimental-options --engine.TraceTransferToInterpreter -c 'print 1;' → Verify no false transfers

After running:

  • Validate: Transfer count within expectation? YES / NO
  • If >100 transfers: CRITICAL - Deoptimization loop, analyze repeated locations
  • Save output: tool-outputs/trace-transfers-[benchmark].txt

Gate: All boxes checked? → Proceed to analysis

Key Options

OptionDescription
--engine.TraceTransferToInterpreterTrace all deoptimizations
--engine.TraceCompilationCombine for full picture
--engine.CompileOnly=<name>Filter to specific function
--engine.TraceStackTraceLimit=<n>Stack trace depth (default 20)

Understanding Output

Transfer Event

code
[engine] transferToInterpreter at
problemFunction(<source>:42:123-456)
callerFunction(<source>:18:78-90)
topLevelFunction(<source>:5:10-50)

Problem Patterns

Pattern 1: Deoptimization Loop (CRITICAL!)

code
[engine] transferToInterpreter at MyNode.execute(<source>:42)
[engine] transferToInterpreter at MyNode.execute(<source>:42)
[engine] transferToInterpreter at MyNode.execute(<source>:42)
...dozens more at same location...

🚨 This is catastrophic! Often worse than never compiling.

Cause: Unstable type assumptions Fix: Implement proper type specializations, avoid mixing types

Pattern 2: Warmup Transfers (Normal)

code
[First 5 seconds]
...many transfers...
[After 10+ seconds]
[No more transfers]  ✅

Acceptable: Decreases over time, stops after warmup

Pattern 3: Rare Path Transfers (Acceptable)

code
[During entire execution]
[engine] transferToInterpreter at errorHandler(<source>:250)

Acceptable: Infrequent, from error handling or validation

Transfer Count Guidelines

CountStatusAction
0✅ PerfectIdeal state
1-10✅ OKLikely warmup or rare paths
10-100⚠️ InvestigateMay have issues
100+❌ CriticalDeoptimization loop likely

Analysis Commands

bash
# Count total transfers
grep -c "transferToInterpreter" transfers.log

# Count unique locations
grep "transferToInterpreter at" transfers.log | sort -u | wc -l

# Find repeated locations (deoptimization loops)
grep "transferToInterpreter at" transfers.log | sort | uniq -c | sort -rn

Integration with Other Skills

FindingNext Skill
Deopt loopsFix type stability, add specializations
Property access deoptsStabilize object shapes
Unclear causeanalyzing-compiler-graphs

Related Skills

  • tracing-compilation-events - See compilation cycles
  • profiling-with-cpu-sampler - Measure impact
  • detecting-performance-warnings - Find barriers
  • analyzing-compiler-graphs - Deep analysis

Reference

bash
<launcher> --help:engine | grep -i transfer

See PATTERNS.md for detailed problem patterns and solutions.