canvas-optimize

canvas-optimize is a skill for Claude Code, Codex from guyulong/cn-agent-skills. It costs 10 tokens per session (1,045 once invoked), scanned A, original, MIT.

A guide to improving the drawing performance of HTML5 Canvas, the browser technology used to render 2D graphics and games.

In plain words
What is it for?
Applying dirty-rectangle rendering, which redraws only changed areas, and using offscreen canvases to cache static content.
Why use it?
It reduces unnecessary redrawing by focusing updates on parts of the canvas that changed, which can help keep interactive graphics responsive.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Applying dirty-rectangle rendering, which redraws only changed areas, and using offscreen canvases to cache static content.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/guyulong/cn-agent-skills/canvas-optimize
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add guyulong/cn-agent-skills --skill canvas-optimize
Clone the repo
git clone --depth 1 https://github.com/guyulong/cn-agent-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for canvas-optimize

README.md
[![agentmods](https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/canvas-optimize/github.svg)](https://agentmods.dev/skills/guyulong/cn-agent-skills/canvas-optimize)
Your own site
<a href="https://agentmods.dev/skills/guyulong/cn-agent-skills/canvas-optimize"><img src="https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/canvas-optimize/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for canvas-optimize

Your own site · 80×15
<a href="https://agentmods.dev/skills/guyulong/cn-agent-skills/canvas-optimize"><img src="https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/canvas-optimize.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 10 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,045 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00010 $0.01045
Opus 5 $0.00005 $0.00522
Sonnet 5 $0.00002 $0.00209
Haiku 4.5 $0.00001 $0.00104

Measured 8d ago against content hash ef124571bdf6, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

canvas-optimize scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/canvas-optimize/SKILL.md · 168 lines

How it starts

The opening of the file, as written. The whole thing — 168 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Canvas渲染优化

使用场景

优化HTML5 Canvas的渲染性能。

核心优化技巧

1. 脏矩形渲染

只重绘发生变化的区域,而非整个画布。

class DirtyRectRenderer {
    constructor(canvas) {
        this.canvas = canvas;
        this.ctx = canvas.getContext('2d');
        this.dirtyRects = [];
    }
    
    markDirty(x, y, w, h) {
        this.dirtyRects.push({ x, y, w, h });
    }
    
    render(drawFunc) {
        if (this.dirtyRects.length === 0) return;
        
        // 合并脏矩形
        const bounds = this.mergeDirtyRects();
        
        // 清除脏区域
        this.ctx.clearRect(bounds.x, bounds.y, bounds.w, bounds.h);
        
        // 只重绘脏区域
        this.ctx.save();
        this.ctx.beginPath();
        this.ctx.rect(bounds.x, bounds.y, bounds.w, bounds.h);
        this.ctx.clip();
        drawFunc();
        this.ctx.restore();
        
        this.dirtyRects = [];
    }
    
    mergeDirtyRects() {
        let minX = Infinity, minY = Infinity;
        let maxX = -Infinity, maxY = -Infinity;
        
        for (const rect of this.dirtyRects) {
            minX = Math.min(minX, rect.x);
            minY = Math.min(minY, rect.y);
            maxX = Math.max(maxX, rect.x + rect.w);
            maxY = Math.max(maxY, rect.y + rect.h);
        }
        
        return { x: minX, y: minY, w: maxX - minX, h: maxY - minY };
    }
}

2. 离屏Canvas

将静态内容渲染到离屏Canvas,然后绘制到主Canvas。

// 创建离屏Canvas
const offscreen = document.createElement('canvas');
offscreen.width = 800;
offscreen.height = 600;
const offCtx = offscreen.getContext('2d');

// 在离屏Canvas上绘制静态内容
function drawStaticContent() {
    offCtx.fillStyle = '#f0f0f0';
    offCtx.fillRect(0, 0, 800, 600);
    // ... 其他静态内容
}

// 主循环中直接绘制离屏Canvas
function render() {
    ctx.drawImage(offscreen, 0, 0);
    // ... 绘制动态内容
}

3. 对象池

避免频繁创建和销毁对象。

class Pool {
    constructor(createFn, resetFn, size = 100) {
        this.createFn = createFn;
        this.resetFn = resetFn;
        this.pool = [];
        for (let i = 0; i < size; i++) {
            this.pool.push(createFn());
        }
    }
    
    get() {
        return this.pool.length > 0 ? this.pool.pop() : this.createFn();
    }
    
    release(obj) {
        this.resetFn(obj);
        this.pool.push(obj);
    }
}

// 使用
const particlePool = new Pool(
    () => ({ x: 0, y: 0, vx: 0, vy: 0, life: 0 }),
    (p) => { p.x = 0; p.y = 0; p.life = 0; }
);

Read the full file on GitHub · 168 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 168 lines · 10 tokens per session scan A ef124571bdf6

Subscribe to this mod's changes

canvas-optimize is a skill published in the GitHub repository guyulong/cn-agent-skills (3 stars, last pushed 3mo ago), licensed MIT. It adds 10 tokens to every session and 1,045 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

hud

Putting numbers, buttons, messages and panels on top of a game — a resource counter, a price, a build button, a toast, a dialog, floating +5s. Use when adding a HUD, an overlay, a score or resource display, a shop button, a notification, a modal; when a tap on the game is being swallowed by the interface; or when the…

plausibleventures/lattice · 89 tokens

worker-visualizer

A real-time data/particle/simulation visualizer whose heavy compute runs in a Web Worker (off the main thread), optionally sharing memory with the UI via SharedArrayBuffer, and renders to a canvas at 60fps. Produced as a single self-contained index.html. Use when the brief asks for a "web worker", "simulation"…

nexu-io/open-design · 123 tokens

article-magazine

Huashu / huashu-md-html-inspired magazine article layout for turning Markdown or notes into a polished long-form HTML essay.

nexu-io/open-design · 30 tokens

react-three-fiber

React Three Fiber 3D renderer for json-render. Use when working with @json-render/react-three-fiber, building 3D scenes from JSON specs, rendering meshes/lights/models/environments, or integrating Three.js with json-render catalogs.

vercel-labs/json-render · 54 tokens

matterjs

Use when implementing 2D physics interactions with Matter.js, including Engine/World setup, Render/Runner configuration, adding bodies and constraints, and scroll/interaction-friendly canvas scenes.

MengTo/Skills · 39 tokens

vgpu

Build, debug, test, and optimize WebGPU projects using vgpu, its CLI, or @vgpu packages. Use for vgpu API questions, WGSL workflows, browser or Node rendering, integrations, testing, and performance work.

vercel-labs/vgpu · 51 tokens