Skip to content

Refine NewNormalizedSimplexFractalNoise - #77

Merged
trevorftp merged 3 commits into
StratumServer:mainfrom
tehtelev:main
Jul 1, 2026
Merged

Refine NewNormalizedSimplexFractalNoise#77
trevorftp merged 3 commits into
StratumServer:mainfrom
tehtelev:main

Conversation

@tehtelev

@tehtelev tehtelev commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Here are the main code changes that have virtually eliminated GC garbage generation:

  • Replacing local allocations with a thread-static cache. Instead of creating new arrays (OctaveEntry[], PastEvaluation[], double[] maxValues, int[] order) in the constructor of each ColumnNoise, static fields with the [ThreadStatic] attribute are now used. Arrays are allocated once per thread and reused for all subsequent calls.

  • Lazy initialization and cache expansion. When first accessed from a thread, arrays are created with a size of Max(48, number of octaves). If more octaves are needed in the future, the arrays are automatically expanded. This covers all real-world configurations without unnecessary allocations.

  • Fixing the actual number of used octaves (nUsedOctaves). The nUsedOctaves field has been added, storing the exact number of active octaves. All loops (NoiseSign, Noise) now iterate up to this limit, rather than up to the array length. This allows for safe use of larger reusable arrays.

  • Resetting state via overwriting. Data from previous evaluations (pastEvaluations) is overwritten in place. Unused elements are simply not read due to the loop limit of nUsedOctaves.

This PR has also been sent to the game developers.

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

Testing on 10,200 generation column chunks:

  • GC load: decreased from 10.22 Gb to 250 MB

Comparisons of execution times are impossible because these modifications are performed in parallel threads, which the OS may manage differently each time. The only noticeable difference is the GC runtime.

Before
newnormalize before mem
newnormalize before trace
2026-07-01_08-50-51
2026-07-01_08-49-37
2026-07-01_08-48-18

After
newnormalize after mem
newnormalize after trace
2026-07-01_08-38-00
2026-07-01_08-38-49
2026-07-01_08-39-32

@tehtelev
tehtelev marked this pull request as ready for review July 1, 2026 06:57
@trevorftp
trevorftp self-requested a review July 1, 2026 17:16
@trevorftp trevorftp added type: perf Improves tick time, memory use, or throughput. risk: medium Moderate impact, needs focused validation. status: needs-review Ready for maintainer review. labels Jul 1, 2026
@trevorftp trevorftp moved this from Inbox to Review / Testing in Stratum Roadmap Jul 1, 2026
@trevorftp
trevorftp merged commit ffc8653 into StratumServer:main Jul 1, 2026
4 of 6 checks passed
@github-project-automation github-project-automation Bot moved this from Review / Testing to Done in Stratum Roadmap Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium Moderate impact, needs focused validation. status: needs-review Ready for maintainer review. type: perf Improves tick time, memory use, or throughput.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants