- Refactor D3D12 backend and RenderGraph module - Update graphics RHI and core rendering components - Add Random.hlsl shader include - Regenerate API documentation and update user guides
200 lines
7.8 KiB
HTML
200 lines
7.8 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Performance Patterns | GhostEngine </title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="title" content="Performance Patterns | GhostEngine ">
|
|
|
|
|
|
<link rel="icon" href="../favicon.ico">
|
|
<link rel="stylesheet" href="../public/docfx.min.css">
|
|
<link rel="stylesheet" href="../public/main.css">
|
|
<meta name="docfx:navrel" content="../toc.html">
|
|
<meta name="docfx:tocrel" content="toc.html">
|
|
|
|
<meta name="docfx:rel" content="../">
|
|
|
|
|
|
|
|
<meta name="loc:inThisArticle" content="In this article">
|
|
<meta name="loc:searchResultsCount" content="{count} results for "{query}"">
|
|
<meta name="loc:searchNoResults" content="No results for "{query}"">
|
|
<meta name="loc:tocFilter" content="Filter by title">
|
|
<meta name="loc:nextArticle" content="Next">
|
|
<meta name="loc:prevArticle" content="Previous">
|
|
<meta name="loc:themeLight" content="Light">
|
|
<meta name="loc:themeDark" content="Dark">
|
|
<meta name="loc:themeAuto" content="Auto">
|
|
<meta name="loc:changeTheme" content="Change theme">
|
|
<meta name="loc:copy" content="Copy">
|
|
<meta name="loc:downloadPdf" content="Download PDF">
|
|
|
|
<script type="module" src="./../public/docfx.min.js"></script>
|
|
|
|
<script>
|
|
const theme = localStorage.getItem('theme') || 'auto'
|
|
document.documentElement.setAttribute('data-bs-theme', theme === 'auto' ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light') : theme)
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body class="tex2jax_ignore" data-layout="" data-yaml-mime="">
|
|
<header class="bg-body border-bottom">
|
|
<nav id="autocollapse" class="navbar navbar-expand-md" role="navigation">
|
|
<div class="container-xxl flex-nowrap">
|
|
<a class="navbar-brand" href="../index.html">
|
|
<img id="logo" class="svg" src="../logo.svg" alt="GhostEngine">
|
|
GhostEngine
|
|
</a>
|
|
<button class="btn btn-lg d-md-none border-0" type="button" data-bs-toggle="collapse" data-bs-target="#navpanel" aria-controls="navpanel" aria-expanded="false" aria-label="Toggle navigation">
|
|
<i class="bi bi-three-dots"></i>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navpanel">
|
|
<div id="navbar">
|
|
<form class="search" role="search" id="search">
|
|
<i class="bi bi-search"></i>
|
|
<input class="form-control" id="search-query" type="search" disabled placeholder="Search" autocomplete="off" aria-label="Search">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="container-xxl">
|
|
<div class="toc-offcanvas">
|
|
<div class="offcanvas-md offcanvas-start" tabindex="-1" id="tocOffcanvas" aria-labelledby="tocOffcanvasLabel">
|
|
<div class="offcanvas-header">
|
|
<h5 class="offcanvas-title" id="tocOffcanvasLabel">Table of Contents</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#tocOffcanvas" aria-label="Close"></button>
|
|
</div>
|
|
<div class="offcanvas-body">
|
|
<nav class="toc" id="toc"></nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="content">
|
|
<div class="actionbar">
|
|
<button class="btn btn-lg border-0 d-md-none" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocOffcanvas" aria-controls="tocOffcanvas" aria-expanded="false" aria-label="Show table of contents">
|
|
<i class="bi bi-list"></i>
|
|
</button>
|
|
|
|
<nav id="breadcrumb"></nav>
|
|
</div>
|
|
|
|
<article data-uid="">
|
|
<h1 id="performance-patterns">Performance Patterns</h1>
|
|
|
|
<p>This page captures the runtime performance techniques used in <code>Ghost.Entities</code> and how to apply them.</p>
|
|
<h2 id="data-layout">Data Layout</h2>
|
|
<ul>
|
|
<li>Archetype storage uses contiguous component arrays per chunk.</li>
|
|
<li>Chunk memory is fixed-size (<code>Chunk.CHUNK_BUFFER_SIZE</code>) to bound allocations and improve locality.</li>
|
|
<li>Component layouts are precomputed per archetype:
|
|
<ul>
|
|
<li>offset,</li>
|
|
<li>size,</li>
|
|
<li>enable-bit offset,</li>
|
|
<li>version index.</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<p>Why it matters:</p>
|
|
<ul>
|
|
<li>Sequential memory access in inner loops.</li>
|
|
<li>Fewer pointer indirections than object-per-entity layouts.</li>
|
|
</ul>
|
|
<h2 id="structural-cost-model">Structural Cost Model</h2>
|
|
<p>Structural changes are intentionally explicit and potentially expensive.</p>
|
|
<ul>
|
|
<li><code>AddComponent</code> / <code>RemoveComponent</code> move entities between archetypes.</li>
|
|
<li>Removal uses swap-back compaction to keep chunks dense.</li>
|
|
<li>Batch destroy path sorts locations and processes by chunk to reduce random work.</li>
|
|
</ul>
|
|
<p>Guidance:</p>
|
|
<ul>
|
|
<li>Prefer bulk creation APIs (<code>CreateEntities</code>) over repeated single inserts.</li>
|
|
<li>Minimize structural churn in hot update loops.</li>
|
|
<li>Use <code>EntityCommandBuffer</code> to defer structural edits.</li>
|
|
</ul>
|
|
<h2 id="query-efficiency">Query Efficiency</h2>
|
|
<ul>
|
|
<li>Queries are compiled into bitset masks.</li>
|
|
<li>Query instances are cached by mask hash in <code>ComponentManager</code>.</li>
|
|
<li>New archetypes are incrementally tested and added to existing query match lists.</li>
|
|
</ul>
|
|
<p>Guidance:</p>
|
|
<ul>
|
|
<li>Build query once, reuse query ID.</li>
|
|
<li>Avoid rebuilding identical queries every frame.</li>
|
|
</ul>
|
|
<h2 id="enableable-components">Enableable Components</h2>
|
|
<p>Enableable state is stored in bitmasks per chunk.</p>
|
|
<ul>
|
|
<li>Toggle with <code>EntityManager.SetEnabled<T>(...)</code>.</li>
|
|
<li>Query semantics (<code>WithAll</code>, <code>WithNone</code>, <code>WithDisabled</code>, <code>WithPresent</code>) combine structural and enablement checks.</li>
|
|
</ul>
|
|
<p>Guidance:</p>
|
|
<ul>
|
|
<li>Prefer enable/disable for state toggles over add/remove where possible.</li>
|
|
</ul>
|
|
<h2 id="change-versioning">Change Versioning</h2>
|
|
<p>The runtime tracks:</p>
|
|
<ul>
|
|
<li>world version (<code>World.Version</code>),</li>
|
|
<li>chunk structural version,</li>
|
|
<li>per-component version per chunk.</li>
|
|
</ul>
|
|
<p><code>ChunkView</code> APIs such as <code>HasChanged<T>(version)</code> allow change-filtered work.</p>
|
|
<p>Guidance:</p>
|
|
<ul>
|
|
<li>Cache last processed version per system/subsystem.</li>
|
|
<li>Skip unchanged chunks/components when possible.</li>
|
|
</ul>
|
|
<h2 id="jobs-and-parallel-chunk-processing">Jobs and Parallel Chunk Processing</h2>
|
|
<p><code>EntityQuery.ScheduleChunkParallel</code> transforms matched chunks into job batches and schedules <code>IJobParallelFor</code> work.</p>
|
|
<p>Guidance:</p>
|
|
<ul>
|
|
<li>Use chunk jobs for broad data transforms.</li>
|
|
<li>Keep <code>batchSize</code> tuned for your workload.</li>
|
|
<li>Chain dependencies correctly and wait only at necessary sync points.</li>
|
|
</ul>
|
|
<h2 id="allocation-and-lifetime-hygiene">Allocation and Lifetime Hygiene</h2>
|
|
<ul>
|
|
<li>Temporary data often uses stack/temporary allocators (<code>AllocationManager.CreateStackScope</code>).</li>
|
|
<li>Persistent containers are explicitly disposed.</li>
|
|
</ul>
|
|
<p>Guidance:</p>
|
|
<ul>
|
|
<li>Keep temporary allocations scoped and short-lived.</li>
|
|
<li>Always dispose worlds, schedulers, and persistent collections deterministically.</li>
|
|
</ul>
|
|
|
|
</article>
|
|
|
|
<div class="contribution d-print-none">
|
|
</div>
|
|
|
|
<div class="next-article d-print-none border-top" id="nextArticle"></div>
|
|
|
|
</div>
|
|
|
|
<div class="affix">
|
|
<nav id="affix"></nav>
|
|
</div>
|
|
</main>
|
|
|
|
<div class="container-xxl search-results" id="search-results"></div>
|
|
|
|
<footer class="border-top text-secondary">
|
|
<div class="container-xxl">
|
|
<div class="flex-fill">
|
|
<span>Made with <a href="https://dotnet.github.io/docfx">docfx</a></span>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|