1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Some performance optimizations (#5424)

* Some performance optimizations

This is globally removing some memory useless copy

* use a const ref return on std::string Settings::get to prevent data copy on getters which doesn't need to copy it
 * pass some stack created strings to static const as they are not modified anywhere
 * Camera: return nametags per const ref instead of a list pointer, we only need to read it
 * INodeDefManager: getAll should be a result ref writer instead of a return copy
 * INodeDefManager: getAlias should return a const std::string ref
 * Minimap: unroll a Scolor creation in blitMinimapPixersToImageRadar to prvent many variable construct/destruct which are unneeded (we rewrite the content in the loop)
 * CNodeDefManager::updateAliases: prevent a idef getall copy
 * Profiler: constness
 * rollback_interface: create real_name later, and use const ref
 * MapBlockMesh updateFastFaceRow: unroll TileSpec next_tile, which has a cost of 1.8% CPU due to variable allocation/destruction,
 * MapBlockMesh updateFastFaceRow: copy next_tile to tile only if it's a different tilespec
 * MapBlockMesh updateFastFaceRow: use memcpy to copy next_lights to lights to do it in a single cpu operation
This commit is contained in:
Loïc Blot 2017-03-22 21:41:02 +01:00 committed by GitHub
parent 9efc5da0fb
commit 072bbba69a
16 changed files with 79 additions and 134 deletions

View file

@ -855,8 +855,9 @@ static void updateFastFaceRow(
makes_face, p_corrected, face_dir_corrected,
lights, tile);
for(u16 j=0; j<MAP_BLOCKSIZE; j++)
{
// Unroll this variable which has a significant build cost
TileSpec next_tile;
for (u16 j = 0; j < MAP_BLOCKSIZE; j++) {
// If tiling can be done, this is set to false in the next step
bool next_is_different = true;
@ -866,12 +867,11 @@ static void updateFastFaceRow(
v3s16 next_p_corrected;
v3s16 next_face_dir_corrected;
u16 next_lights[4] = {0,0,0,0};
TileSpec next_tile;
// If at last position, there is nothing to compare to and
// the face must be drawn anyway
if(j != MAP_BLOCKSIZE - 1)
{
if (j != MAP_BLOCKSIZE - 1) {
p_next = p + translate_dir;
getTileInfo(data, p_next, face_dir,
@ -879,7 +879,7 @@ static void updateFastFaceRow(
next_face_dir_corrected, next_lights,
next_tile);
if(next_makes_face == makes_face
if (next_makes_face == makes_face
&& next_p_corrected == p_corrected + translate_dir
&& next_face_dir_corrected == face_dir_corrected
&& next_lights[0] == lights[0]
@ -894,38 +894,14 @@ static void updateFastFaceRow(
&& tile.emissive_light == next_tile.emissive_light) {
next_is_different = false;
continuous_tiles_count++;
} else {
/*if(makes_face){
g_profiler->add("Meshgen: diff: next_makes_face != makes_face",
next_makes_face != makes_face ? 1 : 0);
g_profiler->add("Meshgen: diff: n_p_corr != p_corr + t_dir",
(next_p_corrected != p_corrected + translate_dir) ? 1 : 0);
g_profiler->add("Meshgen: diff: next_f_dir_corr != f_dir_corr",
next_face_dir_corrected != face_dir_corrected ? 1 : 0);
g_profiler->add("Meshgen: diff: next_lights[] != lights[]",
(next_lights[0] != lights[0] ||
next_lights[0] != lights[0] ||
next_lights[0] != lights[0] ||
next_lights[0] != lights[0]) ? 1 : 0);
g_profiler->add("Meshgen: diff: !(next_tile == tile)",
!(next_tile == tile) ? 1 : 0);
}*/
}
/*g_profiler->add("Meshgen: Total faces checked", 1);
if(makes_face)
g_profiler->add("Meshgen: Total makes_face checked", 1);*/
} else {
/*if(makes_face)
g_profiler->add("Meshgen: diff: last position", 1);*/
}
if(next_is_different)
{
if (next_is_different) {
/*
Create a face if there should be one
*/
if(makes_face)
{
if (makes_face) {
// Floating point conversion of the position vector
v3f pf(p_corrected.X, p_corrected.Y, p_corrected.Z);
// Center point of face (kind of)
@ -957,11 +933,9 @@ static void updateFastFaceRow(
makes_face = next_makes_face;
p_corrected = next_p_corrected;
face_dir_corrected = next_face_dir_corrected;
lights[0] = next_lights[0];
lights[1] = next_lights[1];
lights[2] = next_lights[2];
lights[3] = next_lights[3];
tile = next_tile;
std::memcpy(lights, next_lights, ARRLEN(lights) * sizeof(u16));
if (next_is_different)
tile = next_tile;
p = p_next;
}
}