This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: compose-multiplatform-skiko-vsync-pipeline-synchronization

Compose Multiplatform Skiko VSync Pipeline Synchronization Standard

Enforces strict alignment between Skiko's Skia rendering loop and native platform refresh hardware via iOS CADisplayLink and Android Choreographer. Prevents unsynchronized frame pumping, thread contention, and display pipeline desynchronization that causes frame hitching and jank on heterogeneous refresh displays (e.g., Apple ProMotion 120Hz and Android variable refresh rate).

Prohibited Anti-Pattern: Decoupled Render-Loop Free-Running and Unbound Frame Dispatching

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Compose Multiplatform Skiko VSync Pipeline Synchronization Standard - Enforces strict alignment between Skiko's Skia rendering loop and native platform refresh hardware via iOS CADisplayLink and Android Choreographer. Prevents unsynchronized frame pumping, thread contention, and display pipeline desynchronization that causes frame hitching and jank on heterogeneous refresh displays (e.g., Apple ProMotion 120Hz and Android variable refresh rate).
globs: **/*Skiko*.kt, **/*Render*.kt, **/*Canvas*.kt, **/*Window*.kt, **/iosMain/**/*.kt, **/androidMain/**/*.kt
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/compose-multiplatform-skiko-vsync-pipeline-synchronization"
---

# Compose Multiplatform Skiko VSync Pipeline Synchronization Standard

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Decoupled Render-Loop Free-Running and Unbound Frame Dispatching

## System Constraints
You are a Principal Mobile Architect enforcing Compose Multiplatform Skiko VSync Pipeline Synchronization. Mandate frame-pacing invariants, preventing free-running loops, manual thread sleep timers, and unthrottled frame rendering across iOS and Android runtime targets.

## Strict Guidelines
- Engineers MUST ALWAYS hook the Skiko render dispatcher directly to the platform VSync driver: CADisplayLink on iOS and Choreographer.postFrameCallback on Android.
- Engineers MUST NOT use unconstrained coroutine loops (e.g., `while(isActive) { delay(16); render(); }`) to drive Skiko canvas repaints.
- Engineers MUST configure target CADisplayLink `preferredFrameRateRange` explicitly to support dynamic ProMotion refresh rates (e.g., min: 10, preferred: 120, max: 120) instead of hardcoding 60 FPS intervals.
- Code SHOULD ensure frame invalidation requests (`needRedraw()`) coalesce within the current VSync cycle and avoid multiple rasterization passes per platform hardware tick.
- Services MUST route all Skia canvas surface flush calls on the dedicated rendering thread synchronized to the frame boundary to prevent back-pressure stalls on the main dispatch queue.
- Components NEVER execute long-running CPU blocking or heavy I/O operations inside the Skiko redraw lifecycle callback.

## Bad vs Good Implementations
### Hardware VSync Synchronization via CADisplayLink vs Unbound Timer Loop (iOS)

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using coroutine delay(16) decouples the render clock from the native display refresh rate, causing cumulative phase drift, dropped frames, battery thrashing, and failure to support Apple ProMotion dynamic refresh rates.
```kotlin
// Anti-pattern: Driving Skia render loop via coroutines and manual delay leads to frame hitching and tearing
class UnboundSkikoRenderer(private val skiaLayer: org.jetbrains.skiko.SkiaLayer) {
    private val scope = kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Default)

    fun startRenderLoop() {
        scope.launch {
            while (isActive) {
                // 60fps assumption completely desynchronized from hardware CADisplayLink / ProMotion 120Hz
                skiaLayer.needRedraw()
                kotlinx.coroutines.delay(16) // Drifts relative to iOS VSync cycle
            }
        }
    }
}
```

#### Production Standard (Correct)
> **Standard**: Subscribes directly to CADisplayLink on the main runloop in NSRunLoopCommonModes, exposes full CAFrameRateRange capabilities for ProMotion, and strictly aligns redraw invalidations with the hardware VSync signal.
```kotlin
// Invariant Fix: Explicit integration with CADisplayLink utilizing platform frame timestamps and ProMotion bounds
import platform.QuartzCore.CADisplayLink
import platform.Foundation.NSRunLoop
import platform.Foundation.NSRunLoopCommonModes
import platform.QuartzCore.CAFrameRateRangeMake
import platform.darwin.NSObject
import kotlinx.cinterop.ExportObjCClass
import org.jetbrains.skiko.SkiaLayer

@ExportObjCClass
class HardwareVsyncSkikoPacer(
    private val skiaLayer: SkiaLayer
) : NSObject() {
    private var displayLink: CADisplayLink? = null

    fun attach() {
        val link = CADisplayLink.displayLinkWithTarget(
            target = this,
            selector = platform.objc.sel_registerName("onVsyncTick:")
        )
        // Enable high-fidelity dynamic refresh rates (Apple ProMotion 10Hz-120Hz)
        link.preferredFrameRateRange = CAFrameRateRangeMake(10.0f, 120.0f, 120.0f)
        link.addToRunLoop(NSRunLoop.mainRunLoop, NSRunLoopCommonModes)
        displayLink = link
    }

    @Suppress("UnusedPrivateMember")
    @platform.objc.ObjCAction
    fun onVsyncTick(sender: CADisplayLink) {
        // Coalesce frame request directly at hardware tick boundary
        skiaLayer.needRedraw()
    }

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

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Compose Multiplatform Skiko VSync Pipeline Synchronization Standard

Compose Multiplatform Skiko VSync Pipeline Synchronization Standard defines an industrial-grade behavioral standard for mobile engineering. Enforces strict alignment between Skiko's Skia rendering loop and native platform refresh hardware via iOS CADisplayLink and Android Choreographer. Prevents unsynchronized frame pumping, thread contention, and display pipeline desynchronization that causes frame hitching and jank on heterogeneous refresh displays (e.g., Apple ProMotion 120Hz and Android variable refresh rate). 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 Render-Loop Free-Running and Unbound Frame Dispatching 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 Render-Loop Free-Running and Unbound Frame DispatchingCritical
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 hook the Skiko render dispatcher directly to the platform VSync driver

Engineers MUST ALWAYS hook the Skiko render dispatcher directly to the platform VSync driver: CADisplayLink on iOS and Choreographer.postFrameCallback 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 unconstrained coroutine loops (e.g., `while(isActive) { delay(16)

Engineers MUST NOT use unconstrained coroutine loops (e.g., `while(isActive) { delay(16); render(); }`) to drive Skiko canvas repaints.

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 target CADisplayLink `preferredFrameRateRange` explicitly to support dynamic ProMotion refresh rates (e.g., min

Engineers MUST configure target CADisplayLink `preferredFrameRateRange` explicitly to support dynamic ProMotion refresh rates (e.g., min: 10, preferred: 120, max: 120) instead of hardcoding 60 FPS intervals.

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 ensure frame invalidation requests (`needRedraw()`) coalesce within the current VSync cycle and avoid multiple rasterization passes per platform hardware tick.

Code SHOULD ensure frame invalidation requests (`needRedraw()`) coalesce within the current VSync cycle and avoid multiple rasterization passes per platform hardware tick.

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

Services MUST route all Skia canvas surface flush calls on the dedicated rendering thread synchronized to the frame boundary to prevent back-pressure stalls on the main dispatch queue.

Services MUST route all Skia canvas surface flush calls on the dedicated rendering thread synchronized to the frame boundary to prevent back-pressure stalls on the main dispatch queue.

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.
6

Components NEVER execute long-running CPU blocking or heavy I/O operations inside the Skiko redraw lifecycle callback.

Components NEVER execute long-running CPU blocking or heavy I/O operations inside the Skiko redraw lifecycle callback.

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 VSync Pipeline Synchronization Standard critical for AI coding assistants?

Enforces strict alignment between Skiko's Skia rendering loop and native platform refresh hardware via iOS CADisplayLink and Android Choreographer. Prevents unsynchronized frame pumping, thread contention, and display pipeline desynchronization that causes frame hitching and jank on heterogeneous refresh displays (e.g., Apple ProMotion 120Hz and Android variable refresh rate). 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 Render-Loop Free-Running and Unbound Frame Dispatching) 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