Startup profiles show some small, unnecessary overhead in static initializers creation various ZStat objects, and part of that is due comparing names in ZStatIterableValue::insert even when the insertion order is defined by group name.
gcc doesn't see through strcmp and optimize this so that the strcmp on name is only done when needed, so we need to move the comparison on name into the test:
// First sort by group, then by name
const int group_cmp = strcmp((*current)->group(), group());
if ((group_cmp > 0) || (group_cmp == 0 && strcmp((*current)->name(), name()) > 0)) {
break;
}
This avoids a tiny amount of work (~30k insns) on bootstrap.
Additionally, the sorting can be deferred completely to when starting the ZStat service, which removes the remaining overhead when not running the stat service.
gcc doesn't see through strcmp and optimize this so that the strcmp on name is only done when needed, so we need to move the comparison on name into the test:
// First sort by group, then by name
const int group_cmp = strcmp((*current)->group(), group());
if ((group_cmp > 0) || (group_cmp == 0 && strcmp((*current)->name(), name()) > 0)) {
break;
}
This avoids a tiny amount of work (~30k insns) on bootstrap.
Additionally, the sorting can be deferred completely to when starting the ZStat service, which removes the remaining overhead when not running the stat service.