Skip to content

Snapshots for GenTerraPostProcess - #289

Open
tehtelev wants to merge 1 commit into
StratumServer:indevfrom
tehtelev:gen-post
Open

Snapshots for GenTerraPostProcess#289
tehtelev wants to merge 1 commit into
StratumServer:indevfrom
tehtelev:gen-post

Conversation

@tehtelev

@tehtelev tehtelev commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

We've added a thread-safe snapshot system to GenTerraPostProcess, which caches subchunk data in local arrays once before scanning. This dramatically speeds up world generation: millions of slow GetBlockIdUnsafe calls with palette unpacking are replaced with instant index reads. We've also implemented strict array bounds checking and NullReferenceException protection, completely eliminating rare but critical generator crashes caused by non-standard column heights or missing data in chunks.

Type

  • Bug fix
  • Performance
  • New feature
  • Refactor or cleanup
  • Docs or build

Checklist

  • .\scripts\extract-patches.ps1 ran clean.
  • dotnet build VintageStory.slnx -c Release is green.
  • Every vanilla edit has a // Stratum marker.
  • No vanilla source committed.
  • Tested on a real server start, not just compilation.

Performance numbers

Tested on the generation of 31417 chunk columns (6 threads) by /stratum pregen start radius 100 16000 16000
Seed - seed 1027995113.
World setting - default.

Three runs were performed before and after the changes using the Jetbrains dotTrace program.

Before

  • OnChunkColumnGen method execution time: 5387 ms; 5529 ms; 5561 ms.
  • Average: 5492.3 ms
  • Standard deviation: 92.6 ms

After

  • OnChunkColumnGen method execution time: 3193 ms; 3279 ms; 3236 ms
  • Average: 3236.0 ms
  • Standard deviation: 43.0 ms

Summary: The snapshot optimization resulted in an average speedup of ~41% (dropping execution time from ~5.5 seconds down to ~3.2 seconds). Additionally, the standard deviation dropped from 92.6 ms to 43.0 ms, indicating significantly more stable and predictable chunk generation performance.

@tehtelev
tehtelev marked this pull request as ready for review August 30, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant