Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-performance

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Optimize draw calls: static merge, instancing, dynamic atlases and GPU morph fields. Frame budgets, on-demand rendering, AIR_E_MESH_CAPACITY, AIR_E_PIXEL_RATIO_IMPORT_ORDER.

  • 12 files
  • 84.2 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-performance

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencescontracts.md

≈2.4k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Derived from the cocosair-performance skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.

Contracts

  • There are exactly three batching routes and one instancing macro; no fourth batching API exists (docs/manual/batching-recipes.md:3-10). Shared mesh plus shared material is shared memory, not a shared draw (docs/manual/batching-recipes.md:8). UIStaticBatch resolves by symbol name on the default bundle face (src/cocos/2d/components/ui-static-batch.ts:57) but does nothing: postUpdateAssembler (:85) and markAsDirty (:106) have their bodies commented out and the batcher side setupStaticBatch (src/cocos/2d/renderer/batcher-2d.ts:642), endStaticBatch (:648), commitStaticBatch (:666) have no live caller in src/.
  • BatchingUtility.batchStaticModel(staticModelRoot, batchedRoot) (src/cocos/3d/misc/batch-utils.ts:65) needs at least two MeshRenderer components under the source root; with fewer it logs the number of static models to batch is less than 2,it needn't batch. and returns false (:68-:69). It bakes each world matrix into one merged mesh, sets comp.enabled = false on every source renderer (:91), and adds one MeshRenderer to batchedRoot whose sharedMaterials are copied from the first model (:93-95). Incompatible meshes or materials abort with the meshes of ... and ... can't be merged / the materials of ... and ... can't be merged. After it returns true the source nodes have no live renderer and cannot move or retexture individually; unbatchStaticModel (:108) is the only call that re-enables them and destroys the batched mesh.
  • Dynamic meshes are a post-createAirApp() API: creating or initializing one earlier throws AIR_E_MESH_NOT_READY (src/cocos/3d/misc/create-mesh.ts:265, src/cocos/3d/assets/mesh.ts:416), and Mesh.updateSubMesh on a mesh that is not an initialized dynamic mesh throws the same code with initialize the dynamic mesh before updateSubMesh (src/cocos/3d/assets/mesh.ts:588-590). Reserved capacity comes from { maxSubMeshes: 1, maxSubMeshVertices: 1024, maxSubMeshIndices: 1024 } (src/cocos/3d/misc/mesh-validation.ts:22); AIR_E_MESH_CAPACITY is thrown from six places - option keys (:25), initial vertices (:112), initial indices (:114), update vertices (:40), update attribute bytes (:51), update indices (:61) - and the whole reservation has a 512 MiB ceiling (:118), while a primitiveIndex outside maxSubMeshes throws AIR_E_MESH_PRIMITIVE (:104-:105). Reuse one typed array, refresh bounds every frame and call onGeometryChanged() on the live renderer (examples/shared/batching-routes.ts:91).
  • The only instancing entry is the material define material.initialize({ effectName: 'builtin-unlit', defines: { USE_INSTANCING: true } }) (examples/shared/batching-routes.ts:104); InstancedBuffer is the engine-side accumulator, not the entry (docs/notes/geometry-batching-assessment.md:24). Pass._syncBatchingScheme() (src/cocos/render-scene/core/pass.ts:819-830) rewrites the define to false and drops to BatchingSchemes.NONE with no message when Feature.INSTANCED_ARRAYS is missing, and a per-node material instance resets the macro (src/cocos/render-scene/core/pass-instance.ts:119), so one shared material whose effect declares the macro is mandatory. Capacity is INITIAL_CAPACITY = 32, MAX_CAPACITY = 1024 (src/cocos/rendering/instanced-buffer.ts:58-59) and a full group is skipped so another one is created (:120, :126), so expected draws are Math.ceil(count / 1024) (examples/shared/batching-routes.ts:179); grouping splits on index-buffer objectID, lightmap objectID, reflection-probe fields and stride (src/cocos/rendering/instanced-buffer.ts:113-115). MeshRenderer.setInstancedAttribute (src/cocos/3d/framework/mesh-renderer.ts:733) returns silently while this.model is null, so write after the renderer is active. Instancing removes submit cost, not per-object logic (docs/manual/optimize-lots-of-objects.md:127-128).
  • dynamicAtlasManager ships disabled (src/cocos/2d/utils/dynamic-atlas/atlas-manager.ts:56) because the only enabling code, init() (:169-171), is @internal and nothing calls it; you set enabled = true yourself. That setter runs reset() in both directions, destroying every atlas texture (:72-84), and while enabling subscribes a reset on every scene launch (:77, :162-164). textureSize (2048, :52) and maxAtlasCount (5, :51) setters only store the value, so change them before the first frame is packed. insertSpriteFrame (:183) returns null with no log for a frame that is disabled/atlas-full, already a sub-rectangle (original), packable === false, or uses any sampler other than LINEAR min, LINEAR mag, NONE mip (:188-198); maxFrameSize 512 (:53) and _checkPackable() (src/cocos/2d/assets/sprite-frame.ts:1175-1197) decide the rest.
  • 2D batch identity is dataHash = murmurhash2_32_gc(${bufferId}${layer} ${textureHash}, 666) (src/cocos/2d/renderer/render-data.ts:460-463) and the break predicate also compares material and depth-stencil stage (src/cocos/2d/renderer/batcher-2d.ts:453), with the batch material taken from comp.getRenderMaterial(0) (:465). Batcher2D is not an export name on the default bundle face; the export block lists it as Batcher2D as UI, and the live instance is director.root.batcher2D (src/cocos/root.ts:153). _releaseDescriptorSetCache (src/cocos/2d/renderer/batcher-2d.ts:993) is marked engine-internal and is invoked by texture destruction and label texture replacement; release or replace the texture asset instead of calling it. Batch buffers size from macro.BATCHER2D_MEM_INCREMENT = 144 KB (src/cocos/core/platform/macro.ts:1136).
  • profiler is one module-level singleton (src/cocos/profiler/profiler.ts:617) with no numeric readout API: showStats() (:233), hideStats() (:183), isShowingStats() (:179), setBackgroundColor() (:141), setFontColor() (:152) and the fixed counter set (:74-87) are the whole surface. Both color setters destroy and rebuild a visible panel (:146-149, :157-160), so set them before the first showStats(); hideStats() is a full teardown that nulls the pipeline slot (:186-:229). The overlay is itself scene geometry and renders only when the model exists, is enabled and the pass carries showStatistics (src/cocos/rendering/custom/executor.ts:1282-1283, slot src/cocos/rendering/custom/pipeline.ts:123), and its numbers refresh behind a 500 ms wall-clock gate (src/cocos/profiler/profiler.ts:584-586). setDisplayStats (src/cocos/core/platform/debug.ts:414) and isDisplayStats (:405) are deprecated forwarders.
  • On-demand rendering is pause plus step, not a mode, and it is layered on a loop that always starts continuous (docs/manual/rendering-on-demand.md:6). Subscribe director.once(Director.EVENT_AFTER_DRAW, ...) (src/cocos/game/director.ts:240, emitted right after frameMove) and call game.pause() (src/cocos/game/game.ts:591) inside it: pausing synchronously after app.run(scene) draws zero frames and the event never fires. game.step() is director.tick(this._calculateDT(true)) (:551-552) and advances the fixed frameTime / 1000 (:1048-1050), so set game.frameRate (:416) first. director.pause() (src/cocos/game/director.ts:333) gates only the update block (:795-816) while frameMove keeps running (:818-821), so it cannot stop rendering. game.resume() clears queued input first (src/cocos/game/game.ts:603-605), and pause suspends input dispatch and audio too, so an on-demand scene must name its own wake-up source.
  • pixelRatioCap is a startup-admission option, default 2; finite positive values only. Pass it through createAirApp even when main was imported before creating the canvas. The effective DPR limits framebuffer cost while retaining CSS layout; resolutionScale is a separate quality control.
  • Keep the three capability layers apart. BatchingUtility, Mesh, utils, Material, MeshRenderer, profiler, Profiler, game, director, Director, DynamicAtlasManager, dynamicAtlasManager, AirUIMesh, UIStaticBatch, InstancedBuffer and macro each resolve by symbol name in the single export { ... } block of build/cocosair.module.js; device and Batcher2D do not appear as export names (device is absent, Batcher2D appears aliased as Batcher2D as UI), so device.numDrawCalls (src/cocos/profiler/profiler.ts:590) is only reachable through the overlay row and the 2D batcher only through director.root.batcher2D. Browser-verified ids at candidate fingerprint 2f089f6ce25eaccd are batching-shared, batching-merged, batching-dynamic, batching-utility, profiler-overlay and starfield-galaxy, but the batching-utility entry binds BatchingUtility.batchStaticModel and unbatchStaticModel to the no-runtime-error validator only: that example passes one argument to each call (examples/batching-utility/src/main.ts:85, :93) on a node carrying a single MeshRenderer (:46, :50), so src/cocos/3d/misc/batch-utils.ts:67-69 returns false and the merge path is never exercised there - the two-argument contract above comes from source, not from that id. No recorded entry covers the ?instancing=1 arm, dynamic atlas packing, AirUIMesh batching effects or on-demand stepping, and the recipe p95 table (docs/manual/batching-recipes.md:56-65) reports null GPU and present time (:71-73).

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "draw calls equal the object count",
  "batch many static meshes or UI sprites; createAirInstanceBatch/createAirMorphField point/voxel",
  "measure actual draw counts and frame budget",
  "stop rendering until the next requested frame",
  "high pixel density makes the device too slow"
]
owns
[
  "batching",
  "instancing",
  "dynamic-atlas",
  "profiler",
  "on-demand-rendering",
  "pixel-ratio"
]
not_for
[
  "procedural geometry authoring -> cocosair-primitives-mesh",
  "startup admission and app lifecycle -> cocosair-application",
  "material property types -> cocosair-materials-effects"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "选择静态合批、动态图集和实例化,并检查性能统计、剔除和按需渲染。用于大量对象、动画或绘制性能优化。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-performance