Review the instructions the agent will receive before you install.
Purpose
Use this skill when a test or code path is significantly slower on Kotlin/Native than JVM and you need a reliable, repeatable way to find and fix the lowest-level bottleneck.
Scope
Kotlin Multiplatform projects with JVM + Native targets.
Works best when one target is clearly slower (for example, linuxX64Test vs jvmTest).
Focuses on minimal-risk optimizations that preserve behavior.
Core Principles
Reproduce first, optimize second.
Measure with monotonic clocks, not assumptions.
Always isolate the lowest-level slow step before patching.
Keep patches minimal and reversible.
Prefer compile/test truth over IDE false negatives for expect/actual wiring.
End-to-End Workflow
1. Reproduce with smallest failing/slow test
Run exactly one test method that exhibits slowness.
Keep both target runs comparable (same method, same data).
2. Add phase-level timing in test (coarse)
Use TimeSource.Monotonic.markNow().
Add logs for major phases only first.
Include total elapsed and per-phase elapsed.
3. Compare JVM vs Native and pick worst phase
Identify the phase with the largest native/JVM ratio.
Ignore small differences; chase the dominant hotspot.
4. Add substep timing inside worst phase (fine)
Split compound calls into substeps (a().b() -> time a and b separately).
Iterate until one substep clearly dominates native time.
5. Move instrumentation into production hot function (lowest level)
Add temporary counters around internal branches/subcalls in the suspected function.
Confirm the exact low-level operation causing native overhead.
6. Add dedicated reproducible performance test
Create a small deterministic perf test in relevant test class.
Keep correctness assertions plus one timing output line.
Ensure it exercises the exact hot path repeatedly.