Another performance improvements landed in CMRX codebase. This time we picked up performance potential that was in the build. Performance gains are surprising!
For clarity and for testing purposes, CMRX source code is well organized into a bunch of source files. Some of these source files are portable, some are platform-specific, thus live in completely different directory. This organization is good for clarity, but hurts performance.
When a program written in C programming language is compiled, it is done so per source file. So if a program consists of 20 source files, they are built as 20 individual object files. These are later linked together into binary. CMRX kernel is composed roughly of 20 source files if portable and platform-specific part is combined.
What does this have in common with performance gains? Actually, a lot:
Modern compilers are quite smart when it comes to figuring out how to create smallest / fastest possible binary. If they realize that some function is ever only used once, they may inline it even despite the developer didn’t mark it as inline in the source code. With modern compilers, inline keyword becomes something more like a hint. They may even do the opposite and decide to not inline a function tagged with inline keyword, if it is not a good fit for selected optimization strategy (e.g. optimize for size). Sometimes compilers do even inline functions that are called from various different places. This happens in functions are small and it actually costs more to call the function than to inline it.
And this is exactly where the source code composition enters the show. See? If your source code is split into many small files then compiler can’t figure inlining properly. This is due to the fact that if a function is used from another source file then compiler has no other option than not to inline it. Historically, the only way around this was to have functions in header files, marked as inline.
Later, LTO came. LTO stands for Link-Time Optimization. Briefly: If LTO is enabled, then compiler runs another compiler optimizer pass at link time. It does exactly how it sounds. After everything is compiled and all object files are built, compiler is ran yet again so it can perform optimizations knowing all the compiled object code. This feature is really cool, it can easily strip 30% of binary size and make it faster. It is actually so cool that web browsers are using it by default.
The caveat with LTO is that it isn’t supported so well in the embedded world. When LTO is enabled, compiler does all kind of assumptions on whether function can or can’t be called. This is where embedded poses a problem: We force many objects into binary without being explicitly called. For example, all the interrupt service handlers are only referenced from ISR vector array but never called. That’s why LTO rarely works in embedded world.
There’s third way: Before LTO existed, some projects were leveraging so-called unity builds - all source files are programatically put into one large file and then built as one translation unit. The build is slow because everything is built at once but compiler can figure out inlining and all other optimizations way better than with multiple smaller files.
This is exactly what got implemented in CMRX v0.2.1. CMRX kernel can be built as one translation unit. Doing so will release a lot of optimization potential, yielding smaller and faster kernel.
In fact, when single translation unit build is enabled, CMRX performance surpasses that of FreeRTOS in one of benchmarks we run. CMRX becomes faster at synchronization. Just a tiny bit, yet still faster:
Sure, synchronization isn’t FreeRTOS fastest feature. Our benchmark record for FreeRTOS is also kind-of old with version 10.3.1 being the last we tested. Yet, we are comparing FreeRTOS running completely unprotected with CMRX running completely memory protected!
This is something that will shortly matter more than you think. In december 2027, Cybersecurity Resilience Act is coming into power. This directive has a companion set of harmonized standards which govern design of certain kinds of software. One of them sets basic rules for operating systems. One of the rules laid there (linked document is a draft, may be withdrawn at any time) is that memory protection shall be implemented whenever device is connected to public network and/or can be stolen.
The thing is that virtually all published benchmarks measure raw performance of operating systems without memory protection activated. In 2026 Beningo RTOS Performance Report it is detailed that enabling memory protection in Zephyr may cost anywhere between 40 to 69% of benchmark performance. Even our benchmark results above show that just enabling stack protection in Zephyr causes loss of roughly 40% of scheduler performance score.
These features are on in CMRX by default and cannot even be disabled. So no performance degradation will happen post December 2027 with CMRX.
Actually, it is more probable that opposite will happen. CMRX will further improve its performance as there are still areas where a lot can be improved. And other RTOSes will slow down a lot when memory protection is enabled.
Do you know how fast your RTOS is once memory protection is enabled?
Read more: