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

Skiko Frame Pacing and Native VSync Lock Invariant

Enforces deterministic VSync synchronization between native hardware refresh cycles (CADisplayLink on iOS, platform display clocks on Desktop) and Skiko's Skia-backed rendering pipelines. Prevents frame tearing, dropped redraw buffers, jitter, and excessive GPU queue depth caused by unsynchronized polling loops or decoupled coroutine render drivers.

Prohibited Anti-Pattern: Decoupled Coroutine Loop or Unthrottled Polling Driving Skiko Canvas Redraws

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Skiko Frame Pacing and Native VSync Lock Invariant - Enforces deterministic VSync synchronization between native hardware refresh cycles (CADisplayLink on iOS, platform display clocks on Desktop) and Skiko's Skia-backed rendering pipelines. Prevents frame tearing, dropped redraw buffers, jitter, and excessive GPU queue depth caused by unsynchronized polling loops or decoupled coroutine render drivers.
globs: **/iosApp/**/*.kt, **/desktopMain/**/*.kt, **/skikoMain/**/*.kt, **/ui/**/*.kt
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/skiko-vsync-frame-pacing-guardrail"
---

# Skiko Frame Pacing and Native VSync Lock Invariant

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Decoupled Coroutine Loop or Unthrottled Polling Driving Skiko Canvas Redraws

## System Constraints
You are a Principal Mobile Architect specializing in Compose Multiplatform and graphics engines. You must enforce strict hardware-bound VSync pacing between native display pipelines and the Skiko rendering engine. Reject any implementation that uses arbitrary coroutine delays (e.g., delay(16)), timer loops, or unconstrained render invalidation calls outside the platform's synchronized display callbacks.

## Strict Guidelines
- Engineers MUST ALWAYS bind Skiko draw invalidation directly to native display signals (CADisplayLink on iOS, CVDisplayLink on macOS, or platform-managed swap chains).
- Engineers MUST NOT trigger Skiko render passes inside autonomous coroutines using fixed time steps like `delay(16)` or unconstrained `while(isActive)` loops.
- Code MUST throttle Skia canvas invalidations when the window or view is hidden, occluded, or running in background state to eliminate GPU wake-locks.
- Services MUST ensure that frame timestamps passed to animations originate from native hardware clock ticks rather than host system wall time (`currentTimeMillis()`).
- Components NEVER execute blocking operations, file I/O, or heavy recomposition allocations within the synchronized `onRender` or Skiko draw callbacks.

## Bad vs Good Implementations
### Decoupled Coroutine Loop vs. Hardware-Synchronized Render Driver

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using arbitrary coroutine delays causes phase drift relative to the native refresh rate, missing VSync boundaries. It ignores variable refresh displays (such as Apple ProMotion at 120Hz) and triggers redundant buffer allocations or frame drops.
```kotlin
class CoroutineRenderDriver(private val layer: SkiaLayer) {
    private val scope = CoroutineScope(Dispatchers.Default)

    fun startRendering() {
        scope.launch {
            while (isActive) {
                // Anti-pattern: Fixed delay introduces drift, frame pacing jitter, and GPU queue bloat
                layer.needRedraw()
                delay(16) // Assumes 60Hz and ignores ProMotion (120Hz) or 90Hz hardware displays
            }
        }
    }
}
```

#### Production Standard (Correct)
> **Standard**: Synchronizing Skiko redraws with `CADisplayLink` guarantees deterministic alignment with iOS hardware refresh cycles (including 60Hz and 120Hz ProMotion), minimizes GPU queue latency, and eliminates micro-stutters.
```kotlin
import platform.QuartzCore.CADisplayLink
import platform.Foundation.NSRunLoop
import platform.Foundation.NSRunLoopCommonModes
import org.jetbrains.skiko.SkiaLayer

class HardwareVsyncRenderDriver(
    private val layer: SkiaLayer
) {
    private var displayLink: CADisplayLink? = null

    fun startRendering() {
        // Production Invariant: Synchronize redraw requests directly with native CADisplayLink ticks
        displayLink = CADisplayLink.displayLinkWithTarget(
            target = this,
            selector = platform.objc.sel_registerName("onDisplayTick:")
        ).apply {
            addToRunLoop(NSRunLoop.mainRunLoop, NSRunLoopCommonModes)
        }
    }

    @platform.objc.ObjCAction
    fun onDisplayTick(link: CADisplayLink) {
        // Skiko consumes the hardware frame timestamp, maintaining zero phase drift
        layer.needRedraw()
    }

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

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Skiko Frame Pacing and Native VSync Lock Invariant

Skiko Frame Pacing and Native VSync Lock Invariant defines an industrial-grade behavioral standard for mobile engineering. Enforces deterministic VSync synchronization between native hardware refresh cycles (CADisplayLink on iOS, platform display clocks on Desktop) and Skiko's Skia-backed rendering pipelines. Prevents frame tearing, dropped redraw buffers, jitter, and excessive GPU queue depth caused by unsynchronized polling loops or decoupled coroutine render drivers. 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 Loop or Unthrottled Polling Driving Skiko Canvas Redraws 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 Loop or Unthrottled Polling Driving Skiko Canvas RedrawsCritical
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 Skiko draw invalidation directly to native display signals (CADisplayLink on iOS, CVDisplayLink on macOS, or platform-managed swap chains).

Engineers MUST ALWAYS bind Skiko draw invalidation directly to native display signals (CADisplayLink on iOS, CVDisplayLink on macOS, or platform-managed swap chains).

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 trigger Skiko render passes inside autonomous coroutines using fixed time steps like `delay(16)` or unconstrained `while(isActive)` loops.

Engineers MUST NOT trigger Skiko render passes inside autonomous coroutines using fixed time steps like `delay(16)` or unconstrained `while(isActive)` loops.

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

Code MUST throttle Skia canvas invalidations when the window or view is hidden, occluded, or running in background state to eliminate GPU wake-locks.

Code MUST throttle Skia canvas invalidations when the window or view is hidden, occluded, or running in background state to eliminate GPU wake-locks.

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 ensure that frame timestamps passed to animations originate from native hardware clock ticks rather than host system wall time (`currentTimeMillis()`).

Services MUST ensure that frame timestamps passed to animations originate from native hardware clock ticks rather than host system wall time (`currentTimeMillis()`).

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 execute blocking operations, file I/O, or heavy recomposition allocations within the synchronized `onRender` or Skiko draw callbacks.

Components NEVER execute blocking operations, file I/O, or heavy recomposition allocations within the synchronized `onRender` or Skiko draw callbacks.

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 Skiko Frame Pacing and Native VSync Lock Invariant critical for AI coding assistants?

Enforces deterministic VSync synchronization between native hardware refresh cycles (CADisplayLink on iOS, platform display clocks on Desktop) and Skiko's Skia-backed rendering pipelines. Prevents frame tearing, dropped redraw buffers, jitter, and excessive GPU queue depth caused by unsynchronized polling loops or decoupled coroutine render drivers. 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 Loop or Unthrottled Polling Driving Skiko Canvas Redraws) 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

Skiko