The use of basic classes can very quickly become a performance issue because of data locality issues, confusing the branch predictor, and generally using instructions where C wouldn’t need to.
They’re honestly insignificant compared to the value you get in return, especially with the better typing and application design, but they’re there.
If you stick to the builtin classes, no capturing lambdas, don’t use too many generics, and use const often enough, you should be able to produce code that’s as fast as C. At that point you may as well use C, though, especially because one mistake with semantics and you’re back to hitting C++ related performance issues anyway.
Compile time has got to be part of the convo esp when it comes to the kernel. The Linux kernel is one of the few bits where end-users are actively encouraged to compile from source. It is a feature!
Adding C++ compilitis is pain for what gain, from a kernel pov.
I am not a big fan of c++ overall however that is because other languages have emerged that are sweeter than C that gate some of the people issues with C++.
Anyone who has ever had a thing that was like a thing but not exactly the thing, in C, knows C ain’t great at that.
In this video, we’ll do a deep dive on what C++ Polymorphism is, what “virtual” does under the hood, and ultimately why it is SUCH a performance hit compared to languages like C and Rust.
How is C faster than C++? Unless you use virtual functions, it’s as performant as C. And you definitely wouldn’t use virtual functions in a kernel.
The use of basic classes can very quickly become a performance issue because of data locality issues, confusing the branch predictor, and generally using instructions where C wouldn’t need to.
They’re honestly insignificant compared to the value you get in return, especially with the better typing and application design, but they’re there.
If you stick to the builtin classes, no capturing lambdas, don’t use too many generics, and use
const
often enough, you should be able to produce code that’s as fast as C. At that point you may as well use C, though, especially because one mistake with semantics and you’re back to hitting C++ related performance issues anyway.C++ is only as fast as C if you use only the parts of C++ that are identical to C. In other words, C is faster than C++
You can use compile time polymorphism in C++ without any runtime performance cost.
Compile time has got to be part of the convo esp when it comes to the kernel. The Linux kernel is one of the few bits where end-users are actively encouraged to compile from source. It is a feature!
Adding C++ compilitis is pain for what gain, from a kernel pov.
I am not a big fan of c++ overall however that is because other languages have emerged that are sweeter than C that gate some of the people issues with C++.
Anyone who has ever had a thing that was like a thing but not exactly the thing, in C, knows C ain’t great at that.
Unfortunately, that’s not true
The description says:
This is not about compile-time polymorphism.
Here is an alternative Piped link(s): https://piped.video/watch?v=aq365yzrTVE
Piped is a privacy-respecting open-source alternative frontend to YouTube.
I’m open-source, check me out at GitHub.