This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: compose-skiko-vsync-frame-pacing-invariant-compose-multipla-363

Compose Multiplatform 1.8+ Skiko VSync Frame Pacing Invariant

Enforces strict alignment between Skiko rendering loops and native platform display synchronizers (CADisplayLink on iOS ProMotion and Choreographer on Android dynamic refresh displays). Prohibits unconstrained coroutine frame loops, decoupled ticker clocks, and unconfigured dynamic frame rate ranges in Compose Multiplatform 1.8+ to eliminate micro-stuttering and frame tearing on 120Hz variable refresh rate panels.

Prohibited Anti-Pattern: Decoupled Coroutine Timers and Unconstrained Frame Ticking in Skiko/Compose Render Loops

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Compose Multiplatform 1.8+ Skiko VSync Frame Pacing Invariant - Enforces strict alignment between Skiko rendering loops and native platform display synchronizers (CADisplayLink on iOS ProMotion and Choreographer on Android dynamic refresh displays). Prohibits unconstrained coroutine frame loops, decoupled ticker clocks, and unconfigured dynamic frame rate ranges in Compose Multiplatform 1.8+ to eliminate micro-stuttering and frame tearing on 120Hz variable refresh rate panels.
globs: **/*ViewController.kt, **/*View.kt, **/iosMain/**/*.kt, **/androidMain/**/*.kt, **/skiko/**/*.kt
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/compose-skiko-vsync-frame-pacing-invariant-compose-multipla-363"
---

# Compose Multiplatform 1.8+ Skiko VSync Frame Pacing Invariant

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Decoupled Coroutine Timers and Unconstrained Frame Ticking in Skiko/Compose Render Loops

## System Constraints
You are a Principal Software Architect enforcing the Skiko VSync Frame Pacing Invariant across Compose Multiplatform 1.8+ codebases. Your mandate is to eliminate frame stutter, frame drops, and phase drift caused by artificial delay loops, unmanaged coroutine tickers, or misconfigured CADisplayLink / Choreographer hooks on dynamic 120Hz displays. Reject any PR that uses fixed interval delays for animations, bypasses platform MonotonicFrameClock implementations, or fails to declare ProMotion frame rate ranges on Apple targets.

## Strict Guidelines
- Engineers MUST ALWAYS bind custom animation and render triggers to Compose's MonotonicFrameClock or native platform callbacks (CADisplayLink on iOS, Choreographer on Android).
- Engineers MUST NOT use fixed delays (e.g., delay(16), delay(8), or NSTimer) to pace animations or canvas drawing passes.
- Engineers MUST configure CADisplayLink with preferredFrameRateRange (minimum, preferred, maximum) on iOS 15+ targets to support Apple ProMotion variable refresh rates.
- Code SHOULD verify that Skiko's experimental or platform-specific rendering properties (such as org.jetbrains.skiko.rendering.vsync) are kept enabled and uninterrupted by background coroutines.
- Components NEVER trigger manual Canvas redraws (e.g., invalidate() / setNeedsDisplay()) from off-main threads or un-synchronized coroutine dispatchers.

## Bad vs Good Implementations
### Configuring iOS ComposeUIViewController with Deterministic ProMotion CADisplayLink Frame Pacing

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using hardcoded coroutine delays (delay(16)) ignores the variable refresh rate of ProMotion displays (which range from 10Hz to 120Hz). This leads to frame pacing mismatches, skipped frames, and severe micro-stuttering because frame production is completely decoupled from CADisplayLink ticks.
```kotlin
// Anti-Pattern: Unmanaged coroutine ticker decoupling render updates from CADisplayLink
import androidx.compose.ui.window.ComposeUIViewController
import kotlinx.coroutines.*
import platform.UIKit.UIViewController

fun createStutteringController(): UIViewController {
    val scope = CoroutineScope(Dispatchers.Main)
    scope.launch {
        // Defeats 120Hz ProMotion; introduces micro-stutter via phase misalignment
        while (isActive) {
            delay(16) // Hardcoded 60 FPS assumption
            triggerGlobalCanvasRecomposition()
        }
    }
    return ComposeUIViewController {
        AppContent()
    }
}

fun triggerGlobalCanvasRecomposition() { /* arbitrary state mutation */ }
```

#### Production Standard (Correct)
> **Standard**: By relying on Compose Multiplatform's built-in platform frame pacing and using `withFrameNanos` (backed by iOS `CADisplayLink` and Android `Choreographer`), frame emission is lockstepped to the display hardware. This allows ProMotion displays to run smoothly at 120Hz, dynamically adjust down to 10Hz without stutter, and consume optimal battery.
```kotlin
// Production Invariant: Synchronized MonotonicFrameClock & ProMotion DisplayLink Configuration
import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.window.ComposeUIViewController
import kotlinx.coroutines.*
import platform.QuartzCore.CADisplayLink
import platform.UIKit.UIViewController

fun createPacedComposeController(): UIViewController {
    return ComposeUIViewController(
        configure = {
            // Skiko 1.8+ leverages CADisplayLink directly;
            // enforce full frame synchronization without overriding default platform clocks
            enforceStrictFrameRate = true
        }
    ) {
        AppContent()
    }
}

// When manual frame-synchronized animation driver is required:
suspend fun runDeterministicAnimationLoop(onFrame: (Long) -> Unit) {
    // Bound strictly to platform MonotonicFrameClock (CADisplayLink on iOS, Choreographer on Android)
    while (coroutineContext.isActive) {
        withFrameNanos { frameTimeNanos ->
            onFrame(frameTimeNanos)
        }
    }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Compose Multiplatform 1.8+ Skiko VSync Frame Pacing Invariant

Compose Multiplatform 1.8+ Skiko VSync Frame Pacing Invariant defines an industrial-grade behavioral standard for mobile engineering. Enforces strict alignment between Skiko rendering loops and native platform display synchronizers (CADisplayLink on iOS ProMotion and Choreographer on Android dynamic refresh displays). Prohibits unconstrained coroutine frame loops, decoupled ticker clocks, and unconfigured dynamic frame rate ranges in Compose Multiplatform 1.8+ to eliminate micro-stuttering and frame tearing on 120Hz variable refresh rate panels. 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 Unconstrained Frame Ticking in Skiko/Compose Render Loops 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 Unconstrained Frame Ticking in Skiko/Compose Render LoopsCritical
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 bind custom animation and render triggers to Compose's MonotonicFrameClock or native platform callbacks (CADisplayLink on iOS, Choreographer on Android).

Engineers MUST ALWAYS bind custom animation and render triggers to Compose's MonotonicFrameClock or native platform callbacks (CADisplayLink on iOS, Choreographer on Android).

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 NOT use fixed delays (e.g., delay(16), delay(8), or NSTimer) to pace animations or canvas drawing passes.

Engineers MUST NOT use fixed delays (e.g., delay(16), delay(8), or NSTimer) to pace animations or canvas drawing passes.

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 configure CADisplayLink with preferredFrameRateRange (minimum, preferred, maximum) on iOS 15+ targets to support Apple ProMotion variable refresh rates.

Engineers MUST configure CADisplayLink with preferredFrameRateRange (minimum, preferred, maximum) on iOS 15+ targets to support Apple ProMotion variable refresh rates.

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

Code SHOULD verify that Skiko's experimental or platform-specific rendering properties (such as org.jetbrains.skiko.rendering.vsync) are kept enabled and uninterrupted by background coroutines.

Code SHOULD verify that Skiko's experimental or platform-specific rendering properties (such as org.jetbrains.skiko.rendering.vsync) are kept enabled and uninterrupted by background coroutines.

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 trigger manual Canvas redraws (e.g., invalidate() / setNeedsDisplay()) from off-main threads or un-synchronized coroutine dispatchers.

Components NEVER trigger manual Canvas redraws (e.g., invalidate() / setNeedsDisplay()) from off-main threads or un-synchronized coroutine dispatchers.

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 1.8+ Skiko VSync Frame Pacing Invariant critical for AI coding assistants?

Enforces strict alignment between Skiko rendering loops and native platform display synchronizers (CADisplayLink on iOS ProMotion and Choreographer on Android dynamic refresh displays). Prohibits unconstrained coroutine frame loops, decoupled ticker clocks, and unconfigured dynamic frame rate ranges in Compose Multiplatform 1.8+ to eliminate micro-stuttering and frame tearing on 120Hz variable refresh rate panels. 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 Unconstrained Frame Ticking in Skiko/Compose Render Loops) 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