Skip to content

Optimize T_ID() macro.

Bartosz Podrygajlo requested to merge log-optimization into develop

This changes the way T_IDs are defined. The T_ID macro was using a integer to pointer cast in order to provide type safety. This trick disables some compiler optimizations, as explained here: https://clang.llvm.org/extra/clang-tidy/checks/performance/no-int-to-ptr.html. Removing the type cast reenables the compiler optimizations.

I've attached disassembly benchmark_log.c compiled with and without the optimization present.

unoptimized.txt

optimized.txt

Timing the same executable with and without optimization:

non-optimized:

ubuntu@zeus:~/bpodrygajlo/openairinterface5g/cmake_targets/build$ time ./common/utils/LOG/tests/benchmark_log
[LOG] init aborted, configuration couldn't be performed
log init done
CMDLINE: "./common/utils/LOG/tests/benchmark_log" 
[CONFIG] debug flags: 0x00400000

real    0m1.015s
user    0m1.012s
sys     0m0.003s

optimized:

ubuntu@zeus:~/bpodrygajlo/openairinterface5g/cmake_targets/build$ time ./common/utils/LOG/tests/benchmark_log
[LOG] init aborted, configuration couldn't be performed
log init done
CMDLINE: "./common/utils/LOG/tests/benchmark_log" 
[CONFIG] debug flags: 0x00400000

real    0m0.177s
user    0m0.174s
sys     0m0.003s

The provided testcase doesn't serve a purpose other than showing the optimization so I would remove it if the MR is approved.

Merge request reports