Short circuit chasm noise checks to reduce redundant noise computation. #413
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.
The chasm exporter determines if a block is considered a chasm by performing 3 perlin noise checks and taking the minimum of the three:
final double cavernLikelyhood = Math.min(perlinNoise3.getPerlinNoise(px, py, pz) - bias, Math.min(Math.sin(perlinNoise.getPerlinNoise(px, py, pz) * 25), Math.cos(perlinNoise2.getPerlinNoise(px, py, pz) * 25)) / 2) + 0.5f; // [3] tunnellike
This is done a second time but with a different seed and therefore different perlin noise objects:
final double cavernLikelyhood2 = Math.min(perlinNoise6.getPerlinNoise(px, py, pz) - bias, Math.min(Math.sin(perlinNoise4.getPerlinNoise(px, py, pz) * 25), Math.cos(perlinNoise5.getPerlinNoise(px, py, pz) * 25)) / 2) + 0.5f; // [3] tunnellike
These are eventually used to determine if the point is considered a chasm
processBlock(chunk, x, y, z, (cavernLikelyhood > CHASM_CHANCE) || (cavernLikelyhood2 > CHASM_CHANCE));
What this functionality is effectively doing is checking if all the perlin noises succeed the check against chasm_chance. The problem is that if one of perlin noise checks fails, we still check the other two. Additionally, if the first group of three succeeds, we still check the other group of three regardless.
This is largely an issue since getting perlin noise is very expensive. By making the change to short circuit the individual conditions, I saw the chasm layer CPU time drop by 70% and significantly speed up the export process as a whole.
This change affects both the carve and decorate action but they are largely the same change.This is largely an issue since getting perlin noise is very expensive. By making the change to short circuit the individual conditions, I saw the chasm layer CPU time drop by 70% and significantly speed up the export process as a whole.
This change affects both the carve and decorate action but they are largely the same change. This change affects both the carve and decorate action but they are largely the same change.