perf(core): migrate hot-path incandescence uniforms, rotated mesh caching, and simulation vector churn to core source architectures

Aperta
#540 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
performance

Direzione di ricerca

Read the named renderer files, ColorUtil.cs, ShaderProgram, RotatedMeshCache.cs, the six listed block entity types, WeatherSimulationParticles.cs, and AuroraRenderer to map each phase to existing code. The issue gives no tests or entry point to run, so first identify the relevant allocation paths and available verification. Done means all three phases are migrated with the stated visual parity, ABI compatibility, cache invalidation, and allocation guarantees.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

Recent performance PRs (#510, #511, and #536) successfully mitigated frame-rate drops and memory spikes by patching high-frequency hot paths directly at the call sites. However, addressing these bottlenecks strictly within individual callers leaves the underlying allocating source methods active and duplicates mathematical logic across the codebase.

This issue establishes a 3-phase refactoring to migrate these optimizations to the core source architectures:

  1. Phase 1: Source-Level Zero-Allocation Color & Uniform Pipeline (addressing the source of PR #510 across all 10 item/block renderers).
  2. Phase 2: Standardized Rotated Mesh Cache Architecture for BlockEntities (addressing the source of PR #511 across all 6 rotatable block entities).
  3. Phase 3: Thread-Confined Scratch Buffers and Vector In-Place Mutation (addressing the source of PR #536 across weather and particle simulations).

Technical Scope and Root Causes

Phase 1: Zero-Alloc Incandescence and Color Dispatch in ColorUtil & ShaderProgram

In PR #510, EntityShapeRenderer.RenderItem was patched by inlining temperature clamp math and manual ARGB bit shifts to bypass ColorUtil.GetIncandescenceColorAsColor4f (float[4]) and ColorUtil.ToRGBAVec4f (Vec4f).
However, the source methods in ColorUtil.cs were left allocating, leaving 9 other renderers allocating every single frame:

  • EntityItemRenderer.cs
  • GroundStorageRenderer.cs
  • IngotMoldRenderer.cs
  • ToolMoldRenderer.cs
  • AnvilPartRenderer.cs
  • AnvilWorkItemRenderer.cs
  • ForgeContentsRenderer.cs
  • FirepitContentsRenderer.cs
  • CrucibleInFirepitRenderer.cs

Source Fix:

  • Add non-allocating scalar overloads in ColorUtil:
    public static void GetIncandescenceColor(int temp, out float r, out float g, out float b)
    public static void ArgbToRgbaFloats(int argb, out float r, out float g, out float b, out float a)
  • Retain existing GetIncandescenceColorAsColor4f(int) and ToRGBAVec4f(int) intact for 100% binary mod compatibility.
  • Centralize all 10 renderers to use these zero-alloc methods.
Phase 2: Core RotatedMeshCache for BlockEntities

In PR #511, BEGenericTypedContainer cached rotatedOwnMesh. Other block entities (BESignPost, BELantern, BEAnvil, BEBucket, BEPlantContainer, BEWateringCan) still invoke mesh.Clone().Rotate(...) upon chunk retesselation.

Source Fix:

  • Provide a lightweight RotatedMeshCache struct in VintagestoryApi/Common/Model/RotatedMeshCache.cs that tracks cached MeshData and rotation angles (rotX, rotY, rotZ).
  • Wire cache invalidation into BlockEntity.FromTreeAttributes, OnTransformed, and orientation setters.
  • Migrate the 6 block entity types to consume the shared cache.
Phase 3: In-Place Particle Mutation and Conconfined Simulation Vectors

In PR #536, CloudRendererMap added private reusable vectors. However, WeatherSimulationParticles.cs still allocates new Vec3f(-1f, 3f, -1f) and new Vec3f(2f, 0f, 2f) on every splash tick, and AuroraRenderer allocates vectors inside ribbon generation.

Source Fix:

  • Switch splashParticles to in-place .Set(...) calls matching rainParticle.
  • Confine simulation vectors to thread-local / scratch contexts without breaking the public class contract of Vec3d / Vec3f.

Invariant Guarantees & Verification

  1. Mathematical & Visual Parity: 100% bit-exact temperature glow and color channels (0.0 divergence).
  2. Binary ABI Compatibility: No public methods or types deleted or altered.
  3. Multiplayer State Parity: Complete mesh cache invalidation on network sync.
  4. Zero Heap Allocations: 0 B per-frame allocations across all 10 renderers and particle ticks.
Lingua principale
C#
Stelle
22
Fork
4
Merge medio
30m
PR unite (30g)
188

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di StratumServer/Optimum

Tutte le issue di StratumServer/Optimum

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.