-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix 5 chunk-pipeline performance hotspots #5397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
80ace1f
97891c7
a504c5f
0e7472f
7877691
c012653
271005c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,14 @@ public Vector3f getRenderPosition() { | |
| return new Vector3f(position).mul(Chunks.SIZE_X, Chunks.SIZE_Y, Chunks.SIZE_Z); | ||
| } | ||
|
|
||
| @Override | ||
| public float distanceSquared(float x, float y, float z) { | ||
| float dx = position.x() * Chunks.SIZE_X - x; | ||
| float dy = position.y() * Chunks.SIZE_Y - y; | ||
| float dz = position.z() * Chunks.SIZE_Z - z; | ||
| return dx * dx + dy * dy + dz * dz; | ||
| } | ||
|
Comment on lines
+41
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C 4 'SIZE_[XYZ]|LodChunk\(|new LodChunk|chunk.*(bound|limit|radius)' engine/src/main/javaRepository: MovingBlocks/Terasology Length of output: 50379 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- LodChunk ---'
sed -n '1,110p' engine/src/main/java/org/terasology/engine/world/chunks/LodChunk.java
printf '%s\n' '--- LodChunkProvider coordinate flow ---'
sed -n '1,220p' engine/src/main/java/org/terasology/engine/world/chunks/LodChunkProvider.java
printf '%s\n' '--- Chunks coordinate methods ---'
sed -n '80,180p' engine/src/main/java/org/terasology/engine/world/chunks/Chunks.java
printf '%s\n' '--- coordinate/range declarations and tests ---'
rg -n -C 3 'distanceSquared|scaleDown|world.*(bound|limit|range)|Integer\.MAX_VALUE|Vector3i' engine/src/main/java/org/terasology/engine/world/chunks engine/src/test 2>/dev/null | head -n 240Repository: MovingBlocks/Terasology Length of output: 41511 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- remaining LodChunkProvider coordinate flow ---'
sed -n '200,380p' engine/src/main/java/org/terasology/engine/world/chunks/LodChunkProvider.java
printf '%s\n' '--- Chunks conversion implementation ---'
sed -n '1,90p' engine/src/main/java/org/terasology/engine/world/chunks/Chunks.java
sed -n '180,330p' engine/src/main/java/org/terasology/engine/world/chunks/Chunks.java
printf '%s\n' '--- implementations of chunk world offsets ---'
rg -n -C 5 'getChunkWorldOffsetX|getChunkWorldOffsetY|getChunkWorldOffsetZ|chunkToWorldPosition|scaleDown' engine/src/main/java/org/terasology/engine/world/chunksRepository: MovingBlocks/Terasology Length of output: 36235 Prevent integer overflow in
🤖 Prompt for AI Agents |
||
|
|
||
| @Override | ||
| public AABBfc getAABB() { | ||
| Vector3f min = getRenderPosition(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift
Defer reservation until a render type is used.
This loop reserves both buffers for all four render types before processing any blocks. The surrounding implementation eagerly allocates native buffers, while air blocks can produce no mesh data. Therefore, sparse and empty chunks still allocate buffers for unused render types. (raw.githubusercontent.com)
Move the initial reservation to the first use of each render type, or add lazy reservation in the mesh append path. This preserves the allocation reduction for active render types without adding fixed native memory to every chunk.
🤖 Prompt for AI Agents
Source: MCP tools