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).UIStaticBatchresolves by symbol name on the default bundle face (src/cocos/2d/components/ui-static-batch.ts:57) but does nothing:postUpdateAssembler(:85) andmarkAsDirty(:106) have their bodies commented out and the batcher sidesetupStaticBatch(src/cocos/2d/renderer/batcher-2d.ts:642),endStaticBatch(:648),commitStaticBatch(:666) have no live caller insrc/. BatchingUtility.batchStaticModel(staticModelRoot, batchedRoot)(src/cocos/3d/misc/batch-utils.ts:65) needs at least twoMeshRenderercomponents under the source root; with fewer it logsthe number of static models to batch is less than 2,it needn't batch.and returnsfalse(:68-:69). It bakes each world matrix into one merged mesh, setscomp.enabled = falseon every source renderer (:91), and adds oneMeshRenderertobatchedRootwhosesharedMaterialsare copied from the first model (:93-95). Incompatible meshes or materials abort withthe meshes of ... and ... can't be merged/the materials of ... and ... can't be merged. After it returnstruethe 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 throwsAIR_E_MESH_NOT_READY(src/cocos/3d/misc/create-mesh.ts:265,src/cocos/3d/assets/mesh.ts:416), andMesh.updateSubMeshon a mesh that is not an initialized dynamic mesh throws the same code withinitialize 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_CAPACITYis 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 a512 MiBceiling (:118), while aprimitiveIndexoutsidemaxSubMeshesthrowsAIR_E_MESH_PRIMITIVE(:104-:105). Reuse one typed array, refresh bounds every frame and callonGeometryChanged()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);InstancedBufferis 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 tofalseand drops toBatchingSchemes.NONEwith no message whenFeature.INSTANCED_ARRAYSis 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 isINITIAL_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 areMath.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 whilethis.modelis 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). dynamicAtlasManagerships disabled (src/cocos/2d/utils/dynamic-atlas/atlas-manager.ts:56) because the only enabling code,init()(:169-171), is@internaland nothing calls it; you setenabled = trueyourself. That setter runsreset()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) andmaxAtlasCount(5,:51) setters only store the value, so change them before the first frame is packed.insertSpriteFrame(:183) returnsnullwith 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);maxFrameSize512 (: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 fromcomp.getRenderMaterial(0)(:465).Batcher2Dis not an export name on the default bundle face; the export block lists it asBatcher2D as UI, and the live instance isdirector.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 frommacro.BATCHER2D_MEM_INCREMENT= 144 KB (src/cocos/core/platform/macro.ts:1136). profileris 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 firstshowStats();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 carriesshowStatistics(src/cocos/rendering/custom/executor.ts:1282-1283, slotsrc/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) andisDisplayStats(: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). Subscribedirector.once(Director.EVENT_AFTER_DRAW, ...)(src/cocos/game/director.ts:240, emitted right afterframeMove) and callgame.pause()(src/cocos/game/game.ts:591) inside it: pausing synchronously afterapp.run(scene)draws zero frames and the event never fires.game.step()isdirector.tick(this._calculateDT(true))(:551-552) and advances the fixedframeTime / 1000(:1048-1050), so setgame.frameRate(:416) first.director.pause()(src/cocos/game/director.ts:333) gates only the update block (:795-816) whileframeMovekeeps 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. pixelRatioCapis 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,InstancedBufferandmacroeach resolve by symbol name in the singleexport { ... }block ofbuild/cocosair.module.js;deviceandBatcher2Ddo not appear as export names (deviceis absent,Batcher2Dappears aliased asBatcher2D as UI), sodevice.numDrawCalls(src/cocos/profiler/profiler.ts:590) is only reachable through the overlay row and the 2D batcher only throughdirector.root.batcher2D. Browser-verified ids at candidate fingerprint2f089f6ce25eaccdarebatching-shared,batching-merged,batching-dynamic,batching-utility,profiler-overlayandstarfield-galaxy, but thebatching-utilityentry bindsBatchingUtility.batchStaticModelandunbatchStaticModelto theno-runtime-errorvalidator only: that example passes one argument to each call (examples/batching-utility/src/main.ts:85,:93) on a node carrying a singleMeshRenderer(:46,:50), sosrc/cocos/3d/misc/batch-utils.ts:67-69returnsfalseand 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=1arm, dynamic atlas packing,AirUIMeshbatching 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).