Skip to content

Optimize ColumnNoise with Thread-Local Storage - #84

Open
tehtelev wants to merge 1 commit into
anegostudios:masterfrom
tehtelev:patch-11
Open

Optimize ColumnNoise with Thread-Local Storage#84
tehtelev wants to merge 1 commit into
anegostudios:masterfrom
tehtelev:patch-11

Conversation

@tehtelev

@tehtelev tehtelev commented Jul 1, 2026

Copy link
Copy Markdown

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.

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 07:10
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