This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: cmp-skiko-cadisplaylink-frame-pacing-barrier

Compose Multiplatform Skiko Canvas CADisplayLink VSync Frame-Pacing Barrier

Enforces strict synchronization between Skiko rendering passes and Apple's CADisplayLink to eliminate micro-stuttering, tearing, and thermal throttling on iOS. Mandates explicit CAFrameRateRange configuration for 120Hz ProMotion displays and gates canvas redrawing on actual hardware VSync pulses rather than decoupled Kotlin coroutine timers.

Prohibited Anti-Pattern: Decoupled Coroutine Timers and Unbounded Skiko Redraw Triggers Causing Frame Drops and Battery Drain

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Compose Multiplatform Skiko Canvas CADisplayLink VSync Frame-Pacing Barrier - Enforces strict synchronization between Skiko rendering passes and Apple's CADisplayLink to eliminate micro-stuttering, tearing, and thermal throttling on iOS. Mandates explicit CAFrameRateRange configuration for 120Hz ProMotion displays and gates canvas redrawing on actual hardware VSync pulses rather than decoupled Kotlin coroutine timers.
globs: **/iosMain/**/*.kt, **/appleMain/**/*.kt, iosApp/**/*.swift
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/cmp-skiko-cadisplaylink-frame-pacing-barrier"
---

# Compose Multiplatform Skiko Canvas CADisplayLink VSync Frame-Pacing Barrier

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Decoupled Coroutine Timers and Unbounded Skiko Redraw Triggers Causing Frame Drops and Battery Drain

## System Constraints
You are a Principal Mobile Architect enforcing absolute hardware VSync synchronization for Compose Multiplatform Skiko canvases on iOS. You must mandate that every frame-driven Skiko render pass hooks directly into an active CADisplayLink on NSRunLoop.mainRunLoop using .commonModes. Disallow artificial frame throttling via delay() loops, spinlocks, or unanchored CoroutineScope loops. Require dynamic CAFrameRateRange enablement to properly support Apple ProMotion variable refresh rates (10Hz-120Hz).

## Strict Guidelines
- Engineers MUST ALWAYS drive Skiko custom canvas redraw passes through a native CADisplayLink registered with NSRunLoop.mainRunLoop in NSRunLoopCommonModes.
- Engineers MUST configure preferredFrameRateRange (CAFrameRateRange) explicitly on CADisplayLink instances to support 120Hz ProMotion and prevent 60Hz lock-in.
- Engineers MUST NOT utilize CoroutineScope.launch with delay() or fixed-rate polling loops to simulate frame ticks or orchestrate canvas invalidations.
- Services MUST gate Skiko redraw calls behind dirty-state flags to avoid firing zero-delta render passes on idle CADisplayLink ticks.
- Components NEVER instantiate multiple uncoordinated CADisplayLink instances per UIViewController; frame events must be centralized via a single presentation barrier.

## Bad vs Good Implementations
### Hardware-Synchronized CADisplayLink Barrier for Skiko

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using a coroutine loop with delay(8) is not synchronized with the iOS display subsystem hardware refresh. It causes severe phase-drift jitter, misses CADisplayLink deadlines, prevents ProMotion down-clocking during idle states, and excessively drains battery.
```kotlin
// BAD: Decoupled coroutine timer loop driving canvas invalidation.
// Causes phase-drift with VSync, frame hitching on 120Hz displays, and idle battery drain.
@Composable
fun CanvasAnimationLoop(skikoLayer: SkiaLayer) {
    LaunchedEffect(Unit) {
        while (isActive) {
            skikoLayer.needRedraw()
            delay(8) // Naive ~120Hz target: lacks phase lock, drifts, triggers dropped frames
        }
    }
}
```

#### Production Standard (Correct)
> **Standard**: This implementation uses a native CADisplayLink registered with NSRunLoopCommonModes, properly configured with CAFrameRateRange to leverage Apple ProMotion 120Hz. Rendering only occurs when dirty state exists, preventing idle battery drain and eliminating frame phase drift.
```kotlin
// GOOD: Hardware-aligned CADisplayLink barrier with ProMotion dynamic refresh rates
import platform.QuartzCore.CADisplayLink
import platform.QuartzCore.CAFrameRateRangeMake
import platform.Foundation.NSRunLoop
import platform.Foundation.NSRunLoopCommonModes
import platform.darwin.NSObject
import org.jetbrains.skiko.SkiaLayer

class VSyncFramePacer(
    private val skiaLayer: SkiaLayer,
    private val isDynamicProMotion: Boolean = true
) : NSObject() {
    private var displayLink: CADisplayLink? = null
    private var isDirty: Boolean = false

    fun start() {
        if (displayLink != null) return
        
        displayLink = CADisplayLink.displayLinkWithTarget(
            target = this,
            selector = platform.objc.sel_registerName("onVSync:")
        ).apply {
            if (isDynamicProMotion) {
                // Enable ProMotion dynamic refresh range (24Hz - 120Hz)
                preferredFrameRateRange = CAFrameRateRangeMake(
                    minimum = 24.0f,
                    maximum = 120.0f,
                    preferred = 120.0f
                )
            }
            addToRunLoop(NSRunLoop.mainRunLoop, NSRunLoopCommonModes)
        }
    }

    fun markDirty() {
        isDirty = true
    }

    @Suppress("Unused")
    fun onVSync(sender: CADisplayLink) {
        if (isDirty) {
            skiaLayer.needRedraw()
            isDirty = false
        }
    }

    fun stop() {
        displayLink?.invalidate()
        displayLink = null
    }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Compose Multiplatform Skiko Canvas CADisplayLink VSync Frame-Pacing Barrier

Compose Multiplatform Skiko Canvas CADisplayLink VSync Frame-Pacing Barrier defines an industrial-grade behavioral standard for mobile engineering. Enforces strict synchronization between Skiko rendering passes and Apple's CADisplayLink to eliminate micro-stuttering, tearing, and thermal throttling on iOS. Mandates explicit CAFrameRateRange configuration for 120Hz ProMotion displays and gates canvas redrawing on actual hardware VSync pulses rather than decoupled Kotlin coroutine timers. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Decoupled Coroutine Timers and Unbounded Skiko Redraw Triggers Causing Frame Drops and Battery Drain Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftDecoupled Coroutine Timers and Unbounded Skiko Redraw Triggers Causing Frame Drops and Battery DrainCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS drive Skiko custom canvas redraw passes through a native CADisplayLink registered with NSRunLoop.mainRunLoop in NSRunLoopCommonModes.

Engineers MUST ALWAYS drive Skiko custom canvas redraw passes through a native CADisplayLink registered with NSRunLoop.mainRunLoop in NSRunLoopCommonModes.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST configure preferredFrameRateRange (CAFrameRateRange) explicitly on CADisplayLink instances to support 120Hz ProMotion and prevent 60Hz lock-in.

Engineers MUST configure preferredFrameRateRange (CAFrameRateRange) explicitly on CADisplayLink instances to support 120Hz ProMotion and prevent 60Hz lock-in.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST NOT utilize CoroutineScope.launch with delay() or fixed-rate polling loops to simulate frame ticks or orchestrate canvas invalidations.

Engineers MUST NOT utilize CoroutineScope.launch with delay() or fixed-rate polling loops to simulate frame ticks or orchestrate canvas invalidations.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Services MUST gate Skiko redraw calls behind dirty-state flags to avoid firing zero-delta render passes on idle CADisplayLink ticks.

Services MUST gate Skiko redraw calls behind dirty-state flags to avoid firing zero-delta render passes on idle CADisplayLink ticks.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER instantiate multiple uncoordinated CADisplayLink instances per UIViewController

Components NEVER instantiate multiple uncoordinated CADisplayLink instances per UIViewController; frame events must be centralized via a single presentation barrier.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Compose Multiplatform Skiko Canvas CADisplayLink VSync Frame-Pacing Barrier critical for AI coding assistants?

Enforces strict synchronization between Skiko rendering passes and Apple's CADisplayLink to eliminate micro-stuttering, tearing, and thermal throttling on iOS. Mandates explicit CAFrameRateRange configuration for 120Hz ProMotion displays and gates canvas redrawing on actual hardware VSync pulses rather than decoupled Kotlin coroutine timers. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Decoupled Coroutine Timers and Unbounded Skiko Redraw Triggers Causing Frame Drops and Battery Drain) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Compose