As the tracer should keep its own impact as low as possible, keeping an eye out for unnecessary memory allocations is vital.
Example:
|
void region_begin(const std::string& region_name, std::string module, std::string file_name, |
called from
|
scorep::region_begin(region, module, file_name, line_number); |
module and file_name are 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_name is then never used as a std::string but converted back to a C-String:
|
file_name.c_str(), line_number); |
So all work is wasted completely
- From
module only a substring (prefix) is used (BTW: using substr instead 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
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
scorep_binding_python/src/scorep.cpp
Line 167 in f9fbd7d
moduleandfile_nameare initially NULL-terminated C-Stringsstd::strings very likely allocation heap memory and copying the contentsfile_nameis then never used as astd::stringbut converted back to a C-String:scorep_binding_python/src/scorep.cpp
Line 33 in f9fbd7d
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 cheaperI'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