Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

docs(performance): static batching has a measured example on dusk-fort

yhh48c7a2fddb46
diff --git a/docs/astro/src/content/docs/performance/static-batching.mdx b/docs/astro/src/content/docs/performance/static-batching.mdx
index 84e54504c..3ab7be2cd 100644
--- a/docs/astro/src/content/docs/performance/static-batching.mdx
+++ b/docs/astro/src/content/docs/performance/static-batching.mdx
@@ -56,3 +56,22 @@ for each merged mesh, how many parts it holds, how many draws they cost before,
memory the copy takes — read the two numbers together.
Use instancing for many copies of one mesh, and static batching for many different meshes.
+
+## A measured example
+
+The `dusk-fort` example (39 meshes, 20 distinct shapes), every mesh marked, in the editor's Play on WebGL2:
+
+| | Not marked | Marked |
+|---|---|---|
+| Draw calls per frame | 18 | 13 |
+| Triangles | 51,313 | 51,313 |
+| CPU frame cost | 1.18 ms | 1.16 ms |
+
+Thirty-six of the meshes merged into nine batches (three were alone in their group). Those nine
+batches stand for 32 draws before instancing and hold 2.05 MB of copied vertices. Instancing
+already did most of the saving here, so the merge's share is the last five draws: a scene made of
+many different pieces gains more than one made of a few repeated ones.
+
+The two frames differ by one level of 255 on 1.1% of the pixels, along geometry edges, from
+the merged vertices being transformed on the CPU in 32-bit floats; run to run the same scene differs on
+0.003%.
diff --git a/docs/astro/src/content/docs/zh-cn/performance/static-batching.mdx b/docs/astro/src/content/docs/zh-cn/performance/static-batching.mdx
index 57c1a0377..b9e89d1d7 100644
--- a/docs/astro/src/content/docs/zh-cn/performance/static-batching.mdx
+++ b/docs/astro/src/content/docs/zh-cn/performance/static-batching.mdx
@@ -53,3 +53,20 @@ world.insert(wall, StaticBatch, {});
次绘制、这份拷贝占多少内存 —— 请把两个数字放在一起看。
同一个网格的许多拷贝用实例化,许多不同的网格用静态合并。
+
+## 一个实测例子
+
+`dusk-fort` 示例(39 个网格、20 种形状),全部标记,在编辑器 Play、WebGL2 下:
+
+| | 不标记 | 标记 |
+|---|---|---|
+| 每帧绘制次数 | 18 | 13 |
+| 三角形 | 51,313 | 51,313 |
+| CPU 帧耗时 | 1.18 ms | 1.16 ms |
+
+36 个网格合并成了 9 个批(另有 3 个在自己的组里只有一个)。这 9 个批在实例化之前对应 32 次绘制,
+复制的顶点占 2.05 MB。这个场景里实例化已经省了大部分,合并多省的是最后 5 次:由许多不同部件
+拼成的场景,比由少数几种重复部件拼成的收益更大。
+
+两帧在 1.1% 的像素上差一级(共 255 级),都在几何边缘,来自合并后的顶点在 CPU 上以 32 位浮点
+变换;同一场景两次运行之间只差 0.003%。