AgentSkillsCN

detecting-performance-warnings

在 Truffle 编译过程中检测优化障碍。精准定位虚拟调用、非常量存储、未解析的类型检查以及 TruffleBoundary 问题等阻碍峰值性能的因素,并通过堆栈跟踪准确标识出这些缺陷的源代码位置。此工具是消除编译警告的必要环节,且仅适用于传统 Truffle DSL 节点(不支持字节码 DSL)。

SKILL.md
--- frontmatter
name: detecting-performance-warnings
description: Detects optimization barriers during Truffle compilation. Identifies virtual calls, non-constant stores, unresolved type checks, and TruffleBoundary issues that prevent peak performance. Reports exact source locations with stack traces. Use as essential step for eliminating compilation warnings. ONLY works with traditional Truffle DSL nodes (NOT Bytecode DSL).

Detecting Performance Warnings

Detects optimization barriers during Truffle compilation. Essential for finding virtual calls, type instabilities, and boundary issues that prevent peak performance.

When to Use This Skill

  • Find optimization barriers preventing compilation
  • Identify virtual calls that should be direct
  • Detect non-constant stores and type check failures
  • Locate TruffleBoundary issues in hot paths

Use EARLY in performance investigation - often reveals root causes quickly.

Quick Start

bash
# Basic warning detection
<launcher> --experimental-options \
  --compiler.TracePerformanceWarnings=all <program>

# Combined with compilation trace (RECOMMENDED)
<launcher> --experimental-options \
  --compiler.TracePerformanceWarnings=all \
  --engine.TraceCompilation \
  <program> 2>&1 | tee warnings.log

⚠️ REQUIRED: Fermi Verification (Every Tool Invocation)

Before running:

  • Pre-calculate: Expected warnings (0-10 for well-optimized code, 0 is ideal)
  • Smoke test: <launcher> --experimental-options --compiler.TracePerformanceWarnings=all -c 'print 1;' → Verify no false warnings

After running:

  • Validate: Warning count within expectation? YES / NO
  • If many warnings (>20): Document each - these are critical optimization barriers
  • Save output: tool-outputs/perf-warnings-[benchmark].txt

Gate: All boxes checked? → Proceed to analysis

Key Options

OptionDescription
--compiler.TracePerformanceWarnings=allAll warning types
--compiler.TracePerformanceWarnings=callCall-related only
--compiler.TracePerformanceWarnings=instanceofType checks only
--compiler.TracePerformanceWarnings=storeStore operations only

Understanding Output

Virtual Call Warning (Critical!)

code
[engine] Performance warning: observed virtual call at
  com.example.CallNode.call(CallNode.java:42)
  Reason: CallTarget is not constant

Fix: Add @Cached for CallTarget lookup.

Type Check Warning

code
[engine] Performance warning: observed type check at
  com.example.TypeNode.execute(TypeNode.java:55)
  Reason: Type is not constant

Fix: Add type-specific specializations.

Store Warning

code
[engine] Performance warning: observed store at
  com.example.StoreNode.execute(StoreNode.java:33)
  Reason: Store is not frame or final field

Fix: Use frame slots or final fields.

Warning Severity

Warning TypeSeverityImpact
Virtual callCriticalBlocks inlining, 10-100x slower
Type checkHighPrevents specialization
StoreMediumMay escape optimization

Integration with Other Skills

FindingNext Skill
Many virtual callsanalyzing-compiler-graphs for details
Type instabilitydetecting-deoptimizations
Still confusedfetching-truffle-documentation

Common Fixes

Virtual Call → Direct Call

java
// ❌ BAD
CallTarget target = lookupFunction(name);
target.call(args);

// ✅ GOOD
@Specialization(guards = "func == cachedFunc")
Object cached(@Cached("func") Function cachedFunc,
              @Cached("cachedFunc.getCallTarget()") CallTarget target) {
    return target.call(args);
}

Type Check → Specialization

java
// ❌ BAD
if (value instanceof Integer) { ... }

// ✅ GOOD
@Specialization
int doInt(int value) { ... }

Related Skills

  • profiling-with-cpu-sampler - Identify hot functions first
  • tracing-compilation-events - See compilation status
  • analyzing-compiler-graphs - Deep IR analysis
  • fetching-truffle-documentation - API reference

Reference

bash
<launcher> --help:compiler:internal | grep -i trace