Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua get_biome_data: calc heat and humidity only once #15715

Merged
merged 1 commit into from
Jan 26, 2025

Conversation

kno10
Copy link
Contributor

@kno10 kno10 commented Jan 25, 2025

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 inside calcBiomeAtPoint, 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

have you any idea whether it is possible to cache the results of biome tests (core.get_biome_data) when it is likely to be called repetitively with closely adjacent positions? core.get_biome_data is suboptimal and evaluates biome noise four times per call, and currently occupies multiple milliseconds of a globalstep with thousands of loaded Minecraft chunks.

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.

Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested, but this looks fine as-is and I don't think testing should be necessary.

@sfan5 sfan5 merged commit bee541f into luanti-org:master Jan 26, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants