Optimize ColumnNoise with Thread-Local Storage - #84
Open
tehtelev wants to merge 1 commit into
Open
Conversation
tehtelev
marked this pull request as ready for review
July 1, 2026 07:10
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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





After




