-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
Description
As the tracer should keep its own impact as low as possible, keeping an eye out for unnecessary memory allocations is vital.
Example:
scorep_binding_python/src/scorep.cpp
Line 23 in f9fbd7d
| void region_begin(const std::string& region_name, std::string module, std::string file_name, |
scorep_binding_python/src/scorep.cpp
Line 167 in f9fbd7d
| scorep::region_begin(region, module, file_name, line_number); |
moduleandfile_nameare initially NULL-terminated C-Strings- For calling the function they are converted to
std::strings very likely allocation heap memory and copying the contents - both are only used in the first region enter, so in most cases the above cost is wasted
file_nameis then never used as astd::stringbut converted back to a C-String:So all work is wasted completelyscorep_binding_python/src/scorep.cpp
Line 33 in f9fbd7d
file_name.c_str(), line_number); - From
moduleonly a substring (prefix) is used (BTW: usingsubstrinstead of the ctor would likely read easier) Using resize instead would avoid an allocation and copy and using the find and substr on the original C-String would make it even cheaper
I'm aware this is a Python tracer so relative performance impact is not as large as for e.g. C++ programs but especially allocations can have a noticeable impact. So as un-C++ it is, I'd recommend using raw C-Strings for those 2 and similar for other functions