Heap optimizations
This is a result of this thread.
Brief overview and considerations.
-
In
cmState
, storeBuiltinCommands
andScriptedCommands
as astd::shared_ptr<std::function>
to avoid copy inGetCommandByExactName()
calls. Now care should be taken not to change whatGetCommandByExactName()
returns, also commands'operator()
should beconst
, i.e. not change inner state because now it's preserved between calls. I have not found any problems but additional review is still required. -
Making
cmListFileFunction
astd::shared_ptr<cmListFileFunctionImpl>
. It avoids a lot of copy operations especially inFunctionBlocker
s. Same as above, if someone really needs copy, now it should be done explicitly. I just created type-alias and changed all places to useopeator->()
. Also, it might be better to leavecmListFileFunction
as it was, createcmListFileFunctionPtr
alias and use it everywhere instead ofcmListFileFunction
.
3rd and 4th commits optimize obviously useless copy operations that were top consumers in heaptrack report when I've fixed previous ones. Here's a benchmark of different join methods.
Also, consider making cmState::BuiltinCommands
and cmState::ScriptedCommands
a std::unordered_map
.
I can't see any reason why it should be a std::map
, their order is not used anywhere.
I also made a benchmark for it.
You can see that querying a std::map
is faster only for a very small(<10) set. Currently,
CMake has ~111 built-in commands and even empty run results in 70+ scripted commands.
If it's approved I can add it to this MR as well.