Lua get_biome_data: calc heat and humidity only once #15715
Merged
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.
At every call to
l_get_biome_data()
, the lua API for getting the biome at a position, heat and humidity are computed twice: once insidecalcBiomeAtPoint
, and then again below to return exact heat and humidity.Because of the perlin noises, this function is fairly expensive, and shows up in flamegraphs.
See, e.g., https://codeberg.org/mineclonia/mineclonia/pulls/2681#issuecomment-2650068
Computing them once each is enough. It makes the function roughly twice as fast (well, there is also a y blending noise additionally, it could potentially even be left out. For example with the valley mapgen, biomes are not exact anyway.