minetest/src
Jozef Behran eb2bda7d0b Optimize string (mis)handling (#8128)
* Optimize statbar drawing

The texture name of the statbar is a string passed by value.
That slows down the client and creates litter in the heap
as the content of the string is allocated there. Convert the
offending parameter to a const reference to avoid the
performance hit.

* Optimize texture cache

There is an unnecessary temporary created when the texture
path is being generated. This slows down the cache each time
a new texture is encountered and it needs to be loaded into
the cache. Additionally, the heap litter created by this
unnecessary temporary is particularly troublesome here as
the following code then piles another string (the resulting
full path of the texture) on top of it, followed by the
texture itself, which both are quite long term objects as
they are subsequently inserted into the cache where they can
remain for quite a while (especially if the texture turns
out to be a common one like dirt, grass or stone).

Use std::string.append to get rid of the temporary which
solves both issues (speed and heap fragmentation).

* Optimize animations in client

Each time an animated node is updated, an unnecessary copy of
the texture name is created, littering the heap with lots of
fragments. This can be specifically troublesome when looking
at oceans or large lava lakes as both of these nodes are
usually animated (the lava animation is pretty visible).
Convert the parameter of GenericCAO::updateTextures to a
const reference to get rid of the unnecessary copy.

There is a comment stating "std::string copy is mandatory as
mod can be a class member and there is a swap on those class
members ... do NOT pass by reference", reinforcing the
belief that the unnecessary copy is in fact necessary.
However one of the first things the code of the method does
is to assign the parameter to its class member, creating
another copy. By rearranging the code a little bit this
"another copy" can then be used by the subsequent code,
getting rid of the need to pass the parameter by value and
thus saving that copying effort.

* Optimize chat console history handling

The GUIChatConsole::replaceAndAddToHistory was getting the
line to work on by value which turns out to be unnecessary.
Get rid of that unnecessary copy by converting the parameter
to a const reference.

* Optimize gui texture setting

The code used to set the texture for GUI components was
getting the name of the texture by value, creating
unnecessary performance bottleneck for mods/games with
heavily textured GUIs. Get rid of the bottleneck by passing
the texture name as a const reference.

* Optimize sound playing code in GUIEngine

The GUIEngine's code receives the specification of the sound
to be played by value, which turns out to be most likely a
mistake as the underlying sound manager interface receives
the same thing by reference. Convert the offending parameter
to a const reference to get rid of the rather bulky copying
effort and the associated performance hit.

* Silence CLANG TIDY warnings for unit tests

Change "std::string" to "const std::string &" to avoid an
unnecessary local value copy, silencing the CLANG TIDY
process.

* Optimize formspec handling

The "formspec prepend" parameter was passed to the formspec
handling code by value, creating unnecessary copy of
std::string and slowing down the game if mods add things like
textured backgrounds for the player inventory and/or other
forms. Get rid of that performance bottleneck by converting
the parameter to a const reference.

* Optimize hotbar image handling

The code that sets the background images for the hotbar is
getting the name of the image by value, creating an
unnecessary std::string copying effort. Fix that by
converting the relevant parameters to const references.

* Optimize inventory deserialization

The inventory manager deserialization code gets the
serialized version of the inventory by value, slowing the
server and the client down when there are inventory updates.
This can get particularly troublesome with pipeworks which
adds nodes that can mess around with inventories
automatically or with mods that have mobs with inventories
that actively use them.

* Optimize texture scaling cache

There is an io::path parameter passed by value in the
procedure used to add images converted from textures,
leading to slowdown when the image is not yet created and
the conversion is thus needed. The performance hit is
quite significant as io::path is similar to std::string
so convert the parameter to a const reference to get rid of
it.

* Optimize translation file loader

Use "std::string::append" when calculating the final index
for the translation table to avoid unnecessary temporary
strings. This speeds the translation file loader up
significantly as std::string uses heap allocation which
tends to be rather slow. Additionally, the heap is no
longer being littered by these unnecessary string
temporaries, increasing performance of code that gets
executed after the translation file loader finishes.

* Optimize server map saving

When the directory structure for the world data is created
during server map saving, an unnecessary value passing of
the directory name slows things down. Remove that overhead
by converting the offending parameter to a const reference.
2019-05-18 17:19:13 +02:00
..
client Optimize string (mis)handling (#8128) 2019-05-18 17:19:13 +02:00
content Optimize string handling in path search (#8098) 2019-03-07 08:20:33 +01:00
database Consistent HP and damage types (#8167) 2019-02-10 23:03:26 +00:00
gui Optimize string (mis)handling (#8128) 2019-05-18 17:19:13 +02:00
irrlicht_changes LINT fixes since recent tooling update 2019-03-14 12:30:13 +01:00
mapgen Optimize random turns in dungeongen (#8129) 2019-04-07 19:08:27 +02:00
network Various network performance improvements (#8125) 2019-04-14 21:56:38 +01:00
script Move HTTP request logging to infostream (#8526) 2019-05-12 17:55:14 +01:00
server Add an activeobject manager to hold active objects (#7939) 2018-12-13 20:18:54 +01:00
threading DragonFly BSD is somewhat identical to FreeBSD (#8159) 2019-02-03 09:53:54 +01:00
unittest Optimize string (mis)handling (#8128) 2019-05-18 17:19:13 +02:00
util util/hex.h: Remove whitespace-only line (#8460) 2019-04-08 19:40:02 +01:00
activeobject.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
activeobjectmgr.h Add an activeobject manager to hold active objects (#7939) 2018-12-13 20:18:54 +01:00
ban.cpp Add unittests on ActiveObject and BanManager class (#6866) 2018-01-01 18:48:52 +01:00
ban.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
chat_interface.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
chat.cpp Fix last performance-type-promotion-in-math-fn problems 2018-04-04 07:42:40 +02:00
chat.h Fix last performance-type-promotion-in-math-fn problems 2018-04-04 07:42:40 +02:00
chatmessage.h Travis: Update clang from 4.0 to 5.0 (#6467) 2017-10-09 11:32:06 +02:00
clientiface.cpp Add Lua methods 'set_rotation()' and 'get_rotation()' (#7395) 2018-11-28 09:38:50 +01:00
clientiface.h Check node updates whether the blocks are known (#7568) 2018-08-16 20:10:34 +02:00
clientsimpleobject.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
cloudparams.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
cmake_config_githash.h.in C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
cmake_config.h.in C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
CMakeLists.txt Find PostgreSQL correctly (#8435) 2019-04-07 18:45:25 +02:00
collision.cpp Move client-specific files to 'src/client' (#7902) 2018-11-28 20:01:49 +01:00
collision.h Client-side autojump. Remove Android-only stepheight autojump (#7228) 2018-11-22 21:47:15 +00:00
config.h Update version correctly again (#6462) 2017-09-26 20:30:42 +02:00
constants.h Customizeable max breath for players (#6411) 2017-09-15 12:18:47 +02:00
content_mapnode.cpp Modernize src/c* src/d* and src/e* files (#6263) 2017-08-17 23:02:50 +02:00
content_mapnode.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
content_nodemeta.cpp C++11 patchset 9: move hardcoded init parameters to class definitions (part 1) (#5984) 2017-06-16 11:25:52 +02:00
content_nodemeta.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
content_sao.cpp PlayerSAO::setHP - Don't call on_hpchange callbacks if HP hasn't changed 2019-04-29 14:08:34 +02:00
content_sao.h Add node field to PlayerHPChangeReason table (#8368) 2019-04-11 20:45:39 +01:00
convert_json.cpp Add online content repository 2018-04-19 20:14:53 +01:00
convert_json.h Update JsonCPP to 1.8.3 (#6466) 2017-09-26 20:30:14 +02:00
craftdef.cpp Use unordered_map instead of map for craft definitions (#8432) 2019-03-31 19:26:17 +02:00
craftdef.h Modernize src/c* src/d* and src/e* files (#6263) 2017-08-17 23:02:50 +02:00
daynightratio.h daynightratio.h: Improve codestyle, minor optimisations (#8453) 2019-04-08 00:37:52 +01:00
debug.cpp Fix some misspellings (#8104) 2019-01-16 13:39:13 +01:00
debug.h Remove DSTACK support (#6346) 2017-08-30 08:09:41 +02:00
defaultsettings.cpp World start time: Move to first full light (day night ratio = 1000) (#8410) 2019-04-13 01:46:38 +01:00
defaultsettings.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
emerge.cpp Fix comments 2019-03-31 20:49:39 +02:00
emerge.h EmergeManager::initMapgens use FATAL_ERROR if and drop boolean return 2019-03-31 20:49:39 +02:00
environment.cpp Raycast: export exact pointing location (#6304) 2018-08-16 20:10:08 +02:00
environment.h Revert "Add an active object step time budget #6721" 2018-01-12 23:47:39 -08:00
event.h event.h: Fix import GCC warning caused by ce87310 2018-03-31 14:33:54 +02:00
exceptions.h Modernize source code: last part (#6285) 2017-08-20 13:30:50 +02:00
face_position_cache.cpp Modernize various files 2017-08-18 07:44:52 +02:00
face_position_cache.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
filesys.cpp Fix a stringop-truncation GCC warning 2018-12-04 12:39:19 +01:00
filesys.h Load files from subfolders in texturepacks 2017-11-17 19:23:08 +00:00
gamedef.h Client eventmanager refactor (#7179) 2018-03-30 18:32:52 +02:00
gameparams.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
genericobject.cpp Consistent HP and damage types (#8167) 2019-02-10 23:03:26 +00:00
genericobject.h Consistent HP and damage types (#8167) 2019-02-10 23:03:26 +00:00
gettext.cpp Modernize various files 2017-08-18 07:44:52 +02:00
gettext.h Fix segfault caused by wrong wgettext() 2018-04-09 16:25:57 +02:00
gettime.h Modernize source code: last part (#6285) 2017-08-20 13:30:50 +02:00
httpfetch.cpp httpfetch: Disable IPv6 here too if requested by settings (#8399) 2019-03-18 15:06:27 +01:00
httpfetch.h Travis: Update clang from 4.0 to 5.0 (#6467) 2017-10-09 11:32:06 +02:00
hud.cpp Minimap: Fix radar restriction broken by 9649e47 2019-02-23 15:54:53 +01:00
hud.h Raise hotbar limit to 32 slots, add associated keybinding options (#7916) 2018-12-02 23:34:29 +01:00
inventory.cpp Revert "Inventory: Make addItem for empty ItemStacks respect max stack size" (#8519) 2019-05-12 18:07:15 +01:00
inventory.h Define operators == and != for ItemStack 2019-05-11 18:48:27 +02:00
inventorymanager.cpp Optimize string (mis)handling (#8128) 2019-05-18 17:19:13 +02:00
inventorymanager.h Optimize string (mis)handling (#8128) 2019-05-18 17:19:13 +02:00
irr_aabb3d.h Revert 6587 - Optimize entity-entity collision (#7539) 2018-07-08 21:30:55 +01:00
irr_ptr.h Add Irrlicht-specific smart pointer (#6814) 2019-04-12 17:27:39 +01:00
irr_v2d.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
irr_v3d.h Revert 6587 - Optimize entity-entity collision (#7539) 2018-07-08 21:30:55 +01:00
irrlichttypes_bloated.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
irrlichttypes_extrabloated.h Use true pitch/yaw/roll rotations without loss of precision by pgimeno (#8019) 2019-02-07 21:26:06 +00:00
irrlichttypes.h Fix Android build (#7873) 2018-11-18 11:48:16 +01:00
itemdef.cpp Proselytize the network. Use IEEE F32 (#8030) 2019-01-03 17:04:26 +01:00
itemdef.h Overlays for wield and inventory images (#6107) 2017-08-25 13:20:53 +02:00
itemgroup.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
itemstackmetadata.cpp Add player:get_meta(), deprecate player attributes (#7202) 2018-04-06 10:52:29 +02:00
itemstackmetadata.h Add player:get_meta(), deprecate player attributes (#7202) 2018-04-06 10:52:29 +02:00
light.cpp Light curve: Simplify and improve code, fix darkened daytime sky (#7693) 2018-09-16 17:59:42 +01:00
light.h Light curve: Simplify and improve code, fix darkened daytime sky (#7693) 2018-09-16 17:59:42 +01:00
log.cpp Fix missing warningstream (or similar problem) (#7034) 2018-03-04 17:34:36 +01:00
log.h Fix --color command line parameter ignorance (#7173) 2019-03-05 08:14:33 +01:00
main.cpp Fix --color command line parameter ignorance (#7173) 2019-03-05 08:14:33 +01:00
map_settings_manager.cpp mapgen: drop mapgen id from child mapgens. 2019-03-31 20:49:39 +02:00
map_settings_manager.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
map.cpp Optimize string (mis)handling (#8128) 2019-05-18 17:19:13 +02:00
map.h Optimize string (mis)handling (#8128) 2019-05-18 17:19:13 +02:00
mapblock.cpp Fix warnings about dungeongen.cpp memcpy() and unused variable in MapBlock::deSerializeNetworkSpecific() (#8122) 2019-01-22 22:13:06 +01:00
mapblock.h Optimize ABM checks. 2018-07-21 03:09:39 -07:00
mapnode.cpp Abort when trying to set a not registered node (#7011) 2019-03-07 08:31:25 +01:00
mapnode.h Abort when trying to set a not registered node (#7011) 2019-03-07 08:31:25 +01:00
mapsector.cpp ServerMap saving: cleanups (#6274) 2017-08-19 11:29:46 +02:00
mapsector.h ServerMap saving: cleanups (#6274) 2017-08-19 11:29:46 +02:00
metadata.cpp Add player:get_meta(), deprecate player attributes (#7202) 2018-04-06 10:52:29 +02:00
metadata.h Add player:get_meta(), deprecate player attributes (#7202) 2018-04-06 10:52:29 +02:00
modchannels.cpp Add session_t typedef + remove unused functions (#6470) 2017-09-27 19:47:36 +02:00
modchannels.h Add session_t typedef + remove unused functions (#6470) 2017-09-27 19:47:36 +02:00
modifiedstate.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
nameidmapping.cpp Code modernization: src/n*, src/o* (#6280) 2017-08-19 11:30:46 +02:00
nameidmapping.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
nodedef.cpp Require 'waving = 3' in a nodedef to apply the liquid waving shader (#8418) 2019-03-27 00:18:43 +00:00
nodedef.h Proselytize the network. Use IEEE F32 (#8030) 2019-01-03 17:04:26 +01:00
nodemetadata.cpp Send only changed node metadata to clients instead of whole mapblock (#5268) 2018-12-04 20:37:48 +01:00
nodemetadata.h Send only changed node metadata to clients instead of whole mapblock (#5268) 2018-12-04 20:37:48 +01:00
nodetimer.cpp Code modernization: src/n*, src/o* (#6280) 2017-08-19 11:30:46 +02:00
nodetimer.h Code modernization: src/n*, src/o* (#6280) 2017-08-19 11:30:46 +02:00
noise.cpp Fix more clang-tidy reported problems for performance-type-promotion-in-math-fn 2018-04-03 21:58:29 +02:00
noise.h Code modernization: src/n*, src/o* (#6280) 2017-08-19 11:30:46 +02:00
objdef.cpp Fix Windows build, clean up included headers 2015-05-22 20:37:59 +02:00
objdef.h Node definition manager refactor (#7016) 2018-02-10 21:04:16 +01:00
object_properties.cpp Consistent HP and damage types (#8167) 2019-02-10 23:03:26 +00:00
object_properties.h Consistent HP and damage types (#8167) 2019-02-10 23:03:26 +00:00
pathfinder.cpp Optimize path finalization in pathfinder (#8100) 2019-01-12 16:57:26 +01:00
pathfinder.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
player.cpp Extend pitch fly mode to swimming (#7943) 2018-12-31 00:07:30 +00:00
player.h Extend pitch fly mode to swimming (#7943) 2018-12-31 00:07:30 +00:00
porting_android.cpp Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282) 2017-08-19 14:25:35 +02:00
porting_android.h Android build fixes for c++11 2018-03-11 16:56:27 +01:00
porting.cpp porting.cpp: better minetest support on BSD 2018-12-11 17:35:39 +01:00
porting.h Add a MSVC / Windows compatible snprintf function (#7353) 2018-07-22 21:56:06 +02:00
profiler.cpp Travis: Update clang from 4.0 to 5.0 (#6467) 2017-10-09 11:32:06 +02:00
profiler.h Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282) 2017-08-19 14:25:35 +02:00
quicktune_shortcutter.h Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282) 2017-08-19 14:25:35 +02:00
quicktune.cpp Use C++11 mutexes only (remove compat code) (#5922) 2017-06-06 16:29:28 +02:00
quicktune.h Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282) 2017-08-19 14:25:35 +02:00
raycast.cpp Ease selection of entities behind nodes (#7739) 2018-10-26 19:23:33 +02:00
raycast.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
reflowscan.cpp Node definition manager refactor (#7016) 2018-02-10 21:04:16 +01:00
reflowscan.h Node definition manager refactor (#7016) 2018-02-10 21:04:16 +01:00
remoteplayer.cpp Consistent HP and damage types (#8167) 2019-02-10 23:03:26 +00:00
remoteplayer.h Fix on_successful_save -> onSuccessfulSave 2019-01-04 11:33:04 +01:00
rollback_interface.cpp Abort when trying to set a not registered node (#7011) 2019-03-07 08:31:25 +01:00
rollback_interface.h Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282) 2017-08-19 14:25:35 +02:00
rollback.cpp Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282) 2017-08-19 14:25:35 +02:00
rollback.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
serialization.cpp compressZlib: don't use a SharedBuffer but a raw u8 * pointer 2017-07-27 07:56:48 +02:00
serialization.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
server.cpp Optimize string (mis)handling (#8128) 2019-05-18 17:19:13 +02:00
server.h Optimize string (mis)handling (#8128) 2019-05-18 17:19:13 +02:00
serverenvironment.cpp Force player save before kicking on player shutdown (#8157) 2019-02-03 09:11:45 +01:00
serverenvironment.h Force player save before kicking on player shutdown (#8157) 2019-02-03 09:11:45 +01:00
serverlist.cpp Update JsonCPP to 1.8.3 (#6466) 2017-09-26 20:30:14 +02:00
serverlist.h Add online content repository 2018-04-19 20:14:53 +01:00
serverobject.cpp Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282) 2017-08-19 14:25:35 +02:00
serverobject.h Consistent HP and damage types (#8167) 2019-02-10 23:03:26 +00:00
settings_translation_file.cpp Update minetest.conf.example and settings_translation_file.cpp (#8278) 2019-02-23 20:24:59 +00:00
settings.cpp Advanced settings noiseparams: Remove '}' left in .conf 2019-01-19 18:31:41 +00:00
settings.h Fix issue Minetest crash when custom font path is not exist 2017-11-08 16:14:00 +01:00
sound.h Proselytize the network. Use IEEE F32 (#8030) 2019-01-03 17:04:26 +01:00
staticobject.cpp ServerEnvironment & StaticObject cleanups 2018-03-09 23:27:26 +01:00
staticobject.h ServerEnvironment & StaticObject cleanups 2018-03-09 23:27:26 +01:00
terminal_chat_console.cpp Modernize source code: last part (#6285) 2017-08-20 13:30:50 +02:00
terminal_chat_console.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
tileanimation.cpp Proselytize the network. Use IEEE F32 (#8030) 2019-01-03 17:04:26 +01:00
tileanimation.h Bump minimal protocol version to 36 (#6319) 2017-08-29 19:26:55 +02:00
tool.cpp Proselytize the network. Use IEEE F32 (#8030) 2019-01-03 17:04:26 +01:00
tool.h Tool.cpp/.h, lua_api/l_util.cpp: Tidy up code and remove dead code 2018-01-03 04:01:15 +00:00
translation.cpp Optimize string (mis)handling (#8128) 2019-05-18 17:19:13 +02:00
translation.h Add clientside translations. 2017-08-24 17:54:10 +02:00
version.cpp Update version correctly again (#6462) 2017-09-26 20:30:42 +02:00
version.h C++ modernize: Pragma once (#6264) 2017-08-17 22:19:39 +02:00
voxel.cpp Node definition manager refactor (#7016) 2018-02-10 21:04:16 +01:00
voxel.h VoxelArea: add_{x,y,z,p} must be static 2018-03-09 23:27:26 +01:00
voxelalgorithms.cpp Fix typo in lighting code since bcdb3d5 2018-03-10 09:37:43 +01:00
voxelalgorithms.h Remove unused light updating code 2018-02-04 03:16:45 +00:00