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.

perf(render): walking a frame's meshes asks nothing by name - a material's per-draw questions were string searches, a still child was decomposed again by every view, and the walk's own clock was most of what it reported

yhh94bc561aadff
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 279e4290a..64dcd7dec 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@ published separately; it ships inside the editor.
### Fixed
+- **Walking a frame's meshes costs less, and the profiler says what it costs.** Every mesh, in every view, asked its material's layout several questions by name (does it read the picture behind it, is its alpha coverage, does it cut out a shadow), each a string search; they are answered once when the layout is registered, and the last material and layout asked for are kept. A child of a model (most of an imported scene's meshes) was decomposed afresh by every view of every frame though its matrix had not changed; it is decomposed again only when it moves. And the mesh walk read the clock at every phase of every mesh while profiled, which was four in ten samples of a profiled frame and most of the time it reported; it is timed whole (the split by phase is the build option `ES_PROFILE_COLLECT_PHASES`). On the Bistro scene at 640x360, the best of seven interleaved runs went from 9.97 to 6.83 ms a frame, and a grid of 4096 meshes on one material from 4.08 to 3.09 ms. `render-submit-cost.mjs --wall` times frames with the profiler off.
- **Sprite and particle shaders compile in the background too.** With `quality.asyncShaderCompile`, mesh and material shaders were compiled without holding a frame, and the batch shader's variants (sprites, text, lit sprites) and the particle shader were not: each was linked in place when first needed, measured at 350 to 490 ms of one frame mid-play under ANGLE. They are deferred the same way now, their texture units set when the link lands. Without the setting nothing changes.
- **A shader warm-up waits for the scene still being made.** `warmShaders` (what `quality.prewarmShaders` runs behind the loading screen) stopped at the first three frames in which nothing was compiling. A ground still painting its pages or a field still growing its cells draws seconds later, with shaders nothing had asked for yet, so whether a scene opened complete depended on which arrived first: of the runs of one lake scene, about half opened at 13 s and went on compiling for eight more, the rest at 25 s and complete. Terrain and Foliage now hold the warm-up while they are preparing, and every run opens complete; `holdShaderWarmup(app, busy)` is how a game's own generated content does the same. The wait is still bounded by `prewarmTimeoutMs`.
- **A ground's layer pictures are read together.** A Terrain with layers is not drawn until every layer's albedo, normal and mask have been read, and they were read one after another. A picture that is an `.esimage` recipe is drawn when it is read, so a ground of four layers with recipes for all three stayed out of sight for as long as twelve drawings took in a row. They are now all asked for at once, and recipes are drawn on as many workers as the device has. How much sooner a ground appears was not timed.
diff --git a/pipeline/src/runtime/gameHost.ts b/pipeline/src/runtime/gameHost.ts
index d143408f5..b445e81f4 100644
--- a/pipeline/src/runtime/gameHost.ts
+++ b/pipeline/src/runtime/gameHost.ts
@@ -690,6 +690,10 @@ async function boot(): Promise<void> {
if (!ends[0] || !ends[1]) return null;
return nav.findWorldPath(ends[0], ends[1]);
},
+ /** Turns the engine's profiler off again, which render(), gpu() and costs() engage: a frame timed after it costs what a player's does. */
+ quiet(): void {
+ module.engine_setCpuProfiling?.(false);
+ },
/**
* What the last frame's renderer counted — the work a picture cannot show.
* A field of props drawn at three levels and one drawn at one look alike
diff --git a/src/esengine/ecs/TransformSystem.hpp b/src/esengine/ecs/TransformSystem.hpp
index 4935d0f59..9228142aa 100644
--- a/src/esengine/ecs/TransformSystem.hpp
+++ b/src/esengine/ecs/TransformSystem.hpp
@@ -295,12 +295,14 @@ private:
flatCollapsed = transform->scale.x == 0 || transform->scale.y == 0
|| (task.parentFlatCollapsed && transform->rotation.x == 0 && transform->rotation.y == 0);
const auto matrix = *task.parentMatrix * math::compose(transform->position, transform->rotation, transform->scale);
- if (changedOut_) {
- ++visited_;
- if (matrix != transform->cachedMatrix_) changedOut_->push_back(task.entity);
+ if (changedOut_) ++visited_;
+ // Only a matrix that changed is decomposed again: the same matrix decomposes to the same world fields, and
+ // a still child of a model (most of a scene's meshes) was decomposed afresh by every view of every frame.
+ if (matrix != transform->cachedMatrix_) {
+ if (changedOut_) changedOut_->push_back(task.entity);
+ transform->cachedMatrix_ = matrix;
+ transform->decomposed_ = false;
}
- transform->cachedMatrix_ = matrix;
- transform->decomposed_ = false;
} else if (keepStatic) {
flatCollapsed = registry.has<FlatGeometryCollapsed>(task.entity);
}
diff --git a/src/esengine/renderer/plugins/MeshPlugin.cpp b/src/esengine/renderer/plugins/MeshPlugin.cpp
index 5093b0181..0467f6238 100644
--- a/src/esengine/renderer/plugins/MeshPlugin.cpp
+++ b/src/esengine/renderer/plugins/MeshPlugin.cpp
@@ -687,17 +687,24 @@ void MeshPlugin::collect(RenderCollectContext& collect_ctx) {
const ShadingMode shading = depthPass ? ShadingMode::Shaded : collect_ctx.shading;
ecs::MeshRenderer shaded;
- // Accumulated, not scoped per mesh: a ScopeTimer pair per phase per entity
- // puts its own cost inside the number it reports. One clock read per
- // boundary, and the end of one phase is the start of the next.
+ // The walk is timed whole: two clock reads a walk. A clock read is a call out to the page (performance.now), and read at
+ // every phase of every mesh it was four of every ten samples of a profiled frame and most of the time it reported - the
+ // collect looked several times dearer than it was. The split by phase is a build option (ES_PROFILE_COLLECT_PHASES) for
+ // whoever needs it and accepts that the clock is then in the number; a profile with function names says more.
const bool timing = FrameProfiler::get().enabled();
+#ifdef ES_PROFILE_COLLECT_PHASES
+ constexpr bool phases = true;
+#else
+ constexpr bool phases = false;
+#endif
f64 phase[5] = {0, 0, 0, 0, 0};
- f64 mark = timing ? es_profile_now_ms() : 0.0;
+ const f64 walkStart = timing ? es_profile_now_ms() : 0.0;
+ f64 mark = timing && phases ? walkStart : 0.0;
u32 walked = 0, coldDecompose = 0, lodGathers = 0, programAsks = 0, instanceRecords = 0;
// Where the scene's opaque meshes went in the choice of a depth prepass: taken, left out for a cut-out or a bent vertex, or no program to be had.
u32 prepassTaken = 0, prepassCutout = 0, prepassBent = 0, prepassNoProgram = 0;
const auto tick = [&](int slot) {
- if (!timing) return;
+ if (!phases || !timing) return;
const f64 now = es_profile_now_ms();
phase[slot] += now - mark;
mark = now;
@@ -1275,15 +1282,17 @@ void MeshPlugin::collect(RenderCollectContext& collect_ctx) {
if (timing) {
auto& profiler = FrameProfiler::get();
- profiler.add("render.collect.mesh.decompose", phase[0]);
- profiler.add("render.collect.mesh.lod", phase[1]);
- profiler.add("render.collect.mesh.bounds", phase[2]);
- profiler.add("render.collect.mesh.program", phase[3]);
- profiler.add("render.collect.mesh.emit", phase[4]);
+ if (phases) {
+ profiler.add("render.collect.mesh.decompose", phase[0]);
+ profiler.add("render.collect.mesh.lod", phase[1]);
+ profiler.add("render.collect.mesh.bounds", phase[2]);
+ profiler.add("render.collect.mesh.program", phase[3]);
+ profiler.add("render.collect.mesh.emit", phase[4]);
+ }
// Which pass walked, how many times, and what the walk cost it: the same meshes are visited once per view of the frame, and the
// total above cannot say which view the time belongs to.
// The profiler keeps the name pointer, so these are literals, one set per purpose.
- const f64 spent = phase[0] + phase[1] + phase[2] + phase[3] + phase[4];
+ const f64 spent = es_profile_now_ms() - walkStart;
switch (ctx.purpose) {
case RenderPurpose::Scene:
profiler.add("render.collect.mesh.scene.walks", 1.0);
diff --git a/src/esengine/renderer/store/MaterialStore.cpp b/src/esengine/renderer/store/MaterialStore.cpp
index 78e545db7..b9971f104 100644
--- a/src/esengine/renderer/store/MaterialStore.cpp
+++ b/src/esengine/renderer/store/MaterialStore.cpp
@@ -35,6 +35,7 @@ void MaterialStore::setResourceManager(resource::ResourceManager* resources) {
}
void MaterialStore::forgetShader(resource::ShaderHandle shader) {
+ forgetLookups();
layouts_.erase(shader.id());
sources_.erase(shader.id());
auto found = mesh_programs_.find(shader.id());
@@ -49,6 +50,7 @@ void MaterialStore::undefine(u32 materialId) {
auto it = materials_.find(materialId);
if (it == materials_.end()) return;
if (it->second.ubo != BufferHandle::Invalid && device_) device_->deleteBuffer(it->second.ubo);
+ forgetLookups();
materials_.erase(it);
}
@@ -58,6 +60,7 @@ void MaterialStore::clear() {
if (rec.ubo != BufferHandle::Invalid) device_->deleteBuffer(rec.ubo);
}
}
+ forgetLookups();
materials_.clear();
layouts_.clear();
sources_.clear();
diff --git a/src/esengine/renderer/store/MaterialStore.hpp b/src/esengine/renderer/store/MaterialStore.hpp
index 5e89cc7f4..0eec77e1f 100644
--- a/src/esengine/renderer/store/MaterialStore.hpp
+++ b/src/esengine/renderer/store/MaterialStore.hpp
@@ -114,6 +114,36 @@ struct MaterialUniformLayout {
std::vector<MaterialParamSlot> params;
std::vector<MaterialTextureSlot> textures;
+ /// What the per-draw questions ask of a layout by name, answered once when it is registered (MaterialStore::registerLayout):
+ /// an index into params or textures, -1 for none. Asked by name, each was a string search per mesh per view per frame.
+ struct Named {
+ i32 sceneColor = -1, sceneDepth = -1; // textures
+ i32 transmission = -1, blendDistance = -1; // params
+ i32 coverage = -1, tip = -1, hairShadow = -1; // params
+ bool coverageIsCutoff = false;
+ } named;
+
+ /** Resolves {@link named} from the names; called whenever params, textures or the special names change. */
+ void resolveNamed() {
+ const auto param = [this](const std::string& n) -> i32 {
+ if (n.empty()) return -1;
+ for (usize i = 0; i < params.size(); ++i) if (params[i].name == n) return static_cast<i32>(i);
+ return -1;
+ };
+ const auto texture = [this](const char* n) -> i32 {
+ for (usize i = 0; i < textures.size(); ++i) if (textures[i].name == n) return static_cast<i32>(i);
+ return -1;
+ };
+ named.sceneColor = texture("u_sceneColor");
+ named.sceneDepth = texture("u_sceneDepthMap");
+ named.transmission = param("u_transmission");
+ named.blendDistance = param("u_blendDistance");
+ named.coverage = param(coverageParam);
+ named.tip = param(tipParam);
+ named.hairShadow = param(hairShadowParam);
+ named.coverageIsCutoff = coverageParam == "u_alphaCutoff";
+ }
+
const MaterialParamSlot* find(const std::string& name) const {
for (const auto& p : params) {
if (p.name == name) return &p;
@@ -265,7 +295,7 @@ public:
bool castsCutoutShadow(u32 materialId) const {
const MaterialRecord* m = find(materialId);
const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
- return layout && layout->coverageParam == "u_alphaCutoff" && alphaIsCoverage(materialId);
+ return layout && layout->named.coverageIsCutoff && alphaIsCoverage(materialId);
}
/// The program that draws @p materialId's CASTER into a shadow map: the engine's depth shader for
@@ -292,7 +322,9 @@ public:
/// device loss, a shader reload) changes the id, and a layout filed under the
/// old one would be unreachable from the material that still names it.
void registerLayout(resource::ShaderHandle shader, MaterialUniformLayout layout) {
- if (shader.isValid()) layouts_[shader.id()] = std::move(layout);
+ if (!shader.isValid()) return;
+ layout.resolveNamed();
+ layouts_[shader.id()] = std::move(layout);
}
/// Pushes a material's resolved render state. Preserves any already-packed constants
@@ -358,8 +390,22 @@ public:
/// The record for @p materialId, or nullptr if the handle is 0 / unregistered.
const MaterialRecord* find(u32 materialId) const {
if (materialId == 0) return nullptr;
+ // Every question about a draw's material asks for it again: the last answer is kept, as layoutFor keeps its own.
+ if (materialId == last_material_id_ && last_material_) return last_material_;
auto it = materials_.find(materialId);
- return it != materials_.end() ? &it->second : nullptr;
+ last_material_id_ = materialId;
+ last_material_ = it != materials_.end() ? &it->second : nullptr;
+ return last_material_;
+ }
+
+ /** A float param of @p m by its layout index, or 0 when there is none or it is not packed. */
+ static f32 paramValue(const MaterialRecord& m, const MaterialUniformLayout& layout, i32 index) {
+ if (index < 0) return 0.0f;
+ const MaterialParamSlot& slot = layout.params[static_cast<usize>(index)];
+ if (slot.offset + sizeof(f32) > m.uboBytes.size()) return 0.0f;
+ f32 value = 0.0f;
+ std::memcpy(&value, m.uboBytes.data() + slot.offset, sizeof(f32));
+ return value;
}
/// Whether @p materialId's shader reads the picture of what is behind it (declares `u_sceneColor`): refraction, a lens, anything
@@ -367,15 +413,11 @@ public:
bool usesSceneColor(u32 materialId) const {
const MaterialRecord* m = find(materialId);
const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
- if (!layout || layout->findTexture("u_sceneColor") == nullptr) return false;
+ if (!layout || layout->named.sceneColor < 0) return false;
// A shader that has a `u_transmission` (the Model shader, whose material is mostly opaque) asks for the copy only while
// the material holds it above zero; one that has none always does.
- const MaterialParamSlot* slot = layout->find("u_transmission");
- if (!slot) return true;
- if (slot->offset + sizeof(f32) > m->uboBytes.size()) return false;
- f32 value = 0.0f;
- std::memcpy(&value, m->uboBytes.data() + slot->offset, sizeof(f32));
- return value > 0.0f;
+ if (layout->named.transmission < 0) return true;
+ return paramValue(*m, *layout, layout->named.transmission) > 0.0f;
}
/// The copy of the opaque scene the frame took for the draws above, or invalid when it took none. Bound to a material's
/// `u_sceneColor` unit unless the material was given a texture of its own there.
@@ -386,14 +428,14 @@ public:
bool usesSceneDepth(u32 materialId) const {
const MaterialRecord* m = find(materialId);
const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
- return layout && layout->findTexture("u_sceneDepthMap") != nullptr;
+ return layout && layout->named.sceneDepth >= 0;
}
/// Whether @p materialId is nothing without that copy: it fades into what is behind it, where water only falls back to a plainer look.
/// Seeing one is why a frame with no chain of its own takes one.
bool needsScenePicture(u32 materialId) const {
const MaterialRecord* m = find(materialId);
const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
- return layout && layout->find("u_blendDistance") != nullptr;
+ return layout && layout->named.blendDistance >= 0;
}
/// The copy of the opaque scene's distances the frame took, or invalid when it took none. Bound to a material's `u_sceneDepthMap` unit.
void setSceneDepth(TextureHandle texture) { sceneDepth_ = texture; }
@@ -403,12 +445,8 @@ public:
bool alphaIsCoverage(u32 materialId) const {
const MaterialRecord* m = find(materialId);
const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
- if (!layout || layout->coverageParam.empty()) return false;
- const MaterialParamSlot* slot = layout->find(layout->coverageParam);
- if (!slot || slot->offset + sizeof(f32) > m->uboBytes.size()) return false;
- f32 value = 0.0f;
- std::memcpy(&value, m->uboBytes.data() + slot->offset, sizeof(f32));
- return value > 0.0f;
+ if (!layout) return false;
+ return paramValue(*m, *layout, layout->named.coverage) > 0.0f;
}
/// Whether @p materialId draws a blended pass over its opaque one: its shader names a tip param and this
@@ -416,23 +454,16 @@ public:
bool hasTipPass(u32 materialId) const {
const MaterialRecord* m = find(materialId);
const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
- if (!layout || layout->tipParam.empty()) return false;
- const MaterialParamSlot* slot = layout->find(layout->tipParam);
- if (!slot || slot->offset + sizeof(f32) > m->uboBytes.size()) return false;
- f32 value = 0.0f;
- std::memcpy(&value, m->uboBytes.data() + slot->offset, sizeof(f32));
- return value > 0.0f;
+ if (!layout) return false;
+ return paramValue(*m, *layout, layout->named.tip) > 0.0f;
}
/// The hair shadow density @p materialId holds (see ParsedShader::hairShadowParam), 0 when its shader has none or it is off.
f32 hairShadowDensity(u32 materialId) const {
const MaterialRecord* m = find(materialId);
const MaterialUniformLayout* layout = m ? layoutFor(m->shaderRef) : nullptr;
- if (!layout || layout->hairShadowParam.empty()) return 0.0f;
- const MaterialParamSlot* slot = layout->find(layout->hairShadowParam);
- if (!slot || slot->offset + sizeof(f32) > m->uboBytes.size()) return 0.0f;
- f32 value = 0.0f;
- std::memcpy(&value, m->uboBytes.data() + slot->offset, sizeof(f32));
+ if (!layout) return 0.0f;
+ const f32 value = paramValue(*m, *layout, layout->named.hairShadow);
return value > 0.0f ? value : 0.0f;
}
@@ -440,8 +471,14 @@ public:
/// The post-process pipeline reads it to pack pass params through the same
/// reflected MaterialConstants block a material would use.
const MaterialUniformLayout* layoutFor(resource::ShaderHandle shader) const {
- auto it = layouts_.find(shader.id());
- return it != layouts_.end() ? &it->second : nullptr;
+ // Asked for the same shader by every mesh on it, several times each: the last answer is kept. Node-based, so an answer
+ // stays where it is while others are added; only an erase moves it, and forgets it (forgetLookups).
+ const u32 id = shader.id();
+ if (id == last_layout_id_ && last_layout_) return last_layout_;
+ auto it = layouts_.find(id);
+ last_layout_id_ = id;
+ last_layout_ = it != layouts_.end() ? &it->second : nullptr;
+ return last_layout_;
}
/// Uploads (when dirty) and binds the material's MaterialConstants UBO at binding 1.
@@ -482,6 +519,12 @@ private:
std::unordered_map<u32, MaterialRecord> materials_;
std::unordered_map<u32, MaterialUniformLayout> layouts_;
+ /// The last material and layout asked for (find, layoutFor); forgotten whenever either map erases (forgetLookups).
+ mutable u32 last_material_id_ = 0;
+ mutable const MaterialRecord* last_material_ = nullptr;
+ mutable u32 last_layout_id_ = 0;
+ mutable const MaterialUniformLayout* last_layout_ = nullptr;
+ void forgetLookups() { last_material_ = nullptr; last_material_id_ = 0; last_layout_ = nullptr; last_layout_id_ = 0; }
/// A material shader's authored source + features, filed under its handle for
/// the same reason the layout is: a rebuilt program changes the id.
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index e84da2e8f..480d7862c 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -4784,4 +4784,6 @@ export const NOTED = {
{"note": "A shader warm-up waits for the scene still being made."},
"perf(render): sprite and particle shaders compile in the background too - the batch shader's variants and the particle shader were linked in place whatever asyncShaderCompile said, a third to half a second of one frame when a lit sprite or the first particle appeared; they are deferred as mesh shaders are, their samplers seeded when the link lands":
{"note": "Sprite and particle shaders compile in the background too."},
+ "perf(render): walking a frame's meshes asks nothing by name - a material's per-draw questions were string searches, a still child was decomposed again by every view, and the walk's own clock was most of what it reported":
+ {"note": "Walking a frame's meshes costs less, and the profiler says what it costs."},
};
diff --git a/tools/render-submit-cost.mjs b/tools/render-submit-cost.mjs
index 3a380faab..35859944d 100644
--- a/tools/render-submit-cost.mjs
+++ b/tools/render-submit-cost.mjs
@@ -40,9 +40,13 @@ const SAMPLES = Number(flag('samples', '5'));
const W = Number(flag('w', '1920'));
const H = Number(flag('h', '1080'));
const TOP = Number(flag('top', '30'));
+/** Function names (substrings, comma separated) whose INCLUSIVE time a profile also reports: every sample with one on its stack. */
+const INCL = flag('incl', '') ? flag('incl', '').split(',') : [];
const PROFILE = argv.includes('--profile');
/** Count every WebGL call per frame: the CPU work a frame hands the browser, which no GPU stall can hide. */
const GLCALLS = argv.includes('--glcalls');
+/** Time frames with the engine's profiler left off: what a frame costs a player, not a profiled one. No scopes are read. */
+const WALL = argv.includes('--wall');
const NO_EXPORT = argv.includes('--no-export');
const ONLY = flag('only', '') ? new Set(flag('only', '').split(',')) : null;
/** A png of the last measured frame, to compare two builds' pictures. */
@@ -150,10 +154,10 @@ async function measure(browser, dir) {
await cdp.send('Profiler.enable');
await cdp.send('Profiler.setSamplingInterval', { interval: 100 });
}
- const result = await page.evaluate(async ({ frames, samples, profile }) => {
+ const result = await page.evaluate(async ({ frames, samples, profile, wall }) => {
const c = window.__estellaCooked;
const sync = () => c.capture().rgba[0];
- c.render(); c.costs();
+ if (!wall) { c.render(); c.costs(); } else if (!c.quiet) throw new Error('this package cannot turn its profiler off (no quiet()): re-export it'); else c.quiet();
await c.step(frames, 1 / 60); sync();
const ms = [];
const scopes = [];
@@ -163,7 +167,7 @@ async function measure(browser, dir) {
await c.step(frames, 1 / 60);
sync();
ms.push((performance.now() - t0) / frames);
- scopes.push(c.costs().native);
+ scopes.push(wall ? {} : c.costs().native);
}
let gl = null;
if (window.__glCalls) {
@@ -171,9 +175,9 @@ async function measure(browser, dir) {
await c.step(frames, 1 / 60);
gl = Object.fromEntries(Object.entries(window.__glCalls).map(([k, v]) => [k, v / frames]));
}
- const costs = c.costs();
- return { ms, scopes, counters: c.render(), systems: costs.systems, gl };
- }, { frames: FRAMES, samples: SAMPLES, profile: PROFILE });
+ const costs = wall ? { systems: [] } : c.costs();
+ return { ms, scopes, counters: wall ? {} : c.render(), systems: costs.systems, gl };
+ }, { frames: FRAMES, samples: SAMPLES, profile: PROFILE, wall: WALL });
let profile = null;
if (cdp) {
await cdp.send('Profiler.start');
@@ -203,7 +207,19 @@ function bySelf(profile) {
self.set(key, (self.get(key) ?? 0) + (dt[i] ?? 0) / 1000);
}
const total = [...self.values()].reduce((a, b) => a + b, 0);
- return { total, rows: [...self.entries()].sort((a, b) => b[1] - a[1]) };
+ const parent = new Map();
+ for (const n of profile.nodes) for (const c of n.children ?? []) parent.set(c, n.id);
+ const inclusive = {};
+ for (const name of INCL) inclusive[name] = 0;
+ for (let i = 0; i < profile.samples.length; i++) {
+ const hit = new Set();
+ for (let id = profile.samples[i]; id !== undefined; id = parent.get(id)) {
+ const fn = byId.get(id).callFrame.functionName;
+ for (const name of INCL) if (fn.includes(name)) hit.add(name);
+ }
+ for (const name of hit) inclusive[name] += (dt[i] ?? 0) / 1000;
+ }
+ return { total, rows: [...self.entries()].sort((a, b) => b[1] - a[1]), inclusive };
}
const browser = await chromium.launch({
@@ -241,6 +257,7 @@ try {
if (r.profile) {
const p = bySelf(r.profile);
console.log(` profile: ${p.total.toFixed(0)} ms sampled`);
+ for (const [name, ms] of Object.entries(p.inclusive)) console.log(` inclusive ${name}: ${ms.toFixed(1)} ms (${(100 * ms / p.total).toFixed(1)}%)`);
for (const [k, v] of p.rows.slice(0, TOP)) console.log(` ${v.toFixed(1).padStart(8)} ms ${(100 * v / p.total).toFixed(1).padStart(5)}% ${k}`);
table[spread].profile = p.rows.slice(0, 200);
}