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.5 $0.00004 $0.00418
Sonnet 5.5 $0.00002 $0.00209
Haiku 4.5 $0.00001 $0.00104

Measured 1mo ago against content hash ef124571bdf6, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 1mo 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. 1mo 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 4mo ago), licensed MIT. It adds 10 tokens to every session and 1,045 once invoked, about $0.0000 per session on Opus 5.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

umg-widgets

Create and modify UMG Widget Blueprints (UI) — build the widget hierarchy, set properties, style fonts/brushes, author widget animations, bind events, capture previews, run PIE checks, and wire MVVM ViewModels. Use when the user asks to create a UI/HUD/menu, add or arrange widgets (Button, TextBlock, Image, panels)…

kevinpbuckley/VibeUE · 98 tokens

ecom-details-image

A guide for planning still images used to sell or explain products, including main product pictures, detail-page images, banners, lifestyle scenes, packaging, comparisons, and product demonstrations. It can provide image prompts or, when explicitly requested, use the project's own image-generation route.

anymouschina/TapCanvas · 200 tokens

tapcanvas-source-coverage

A source-coverage checker for long texts, subtitles, interviews, videos, and collections of files. It records which parts were actually read and links them to evidence that can be checked later.

anymouschina/TapCanvas · 128 tokens

tapcanvas-style-pack

A visual-style planning skill for creating, extracting, applying, updating, or checking a project's reusable look. A style pack describes transferable choices such as colour, lighting, composition, materials, and camera movement without copying the specific content of a reference image.

anymouschina/TapCanvas · 123 tokens

tvc-ad-director

A directing guide for television commercials and other short product or brand adverts. It turns a business goal into one clear message, visual plan, and handoff for production.

anymouschina/TapCanvas · 144 tokens

starting

The wiring order for a Lattice game — canvas, surface, camera, palette, light, depth sorter, loop and input — and the shape a first build should take so it does not come out a diorama. Use when starting an isometric game, setting up a Lattice project, writing the boot or main.ts, adding a game loop to a canvas…

plausibleventures/lattice · 123 tokens