I am wondering if it is still worth using modern compilers and their optimization to write critical code in C instead of C ++ to make it faster.
not. keep it readable. if your team prefers C ++ or c, prefer this, especially if it already works in production code (do not rewrite it for no particular reason).
I know that C ++ can lead to poor performance if classes are copied when they can be passed by reference
then prohibit copying and assignment
or when classes are created automatically by the compiler, usually with overloaded operators and many other similar cases
Could you clarify? if you refer to templates, they have no additional cost at runtime (although they can lead to additional exported characters, which will lead to an increase in the binary file). in fact, using the template method can improve performance if (for example) conversion would otherwise be necessary.
but for a good C ++ developer who knows how to avoid all this, is it still worth writing C code to improve performance?
in my experience, a C ++ expert developer can create a faster and more user-friendly program.
You must be selective about the language features you use (and not use). if you violate C ++ functions before the set available in c (for example, remove exceptions, virtual function calls, rtti), you can start a good start. if you learn to use templates, metaprogramming, optimization methods, avoid type aliases (which gets harder or harder in c), etc., then you should be at or faster than c with a program that is more easily supported ( since you are familiar with C ++).
if you are comfortable using C ++ functions, use C ++. it has many features (many of which are added at speed / cost), and they can be written as fast as c (or faster).
With templates and metaprogramming, you can turn many variables at runtime into compile-time constants for exceptional achievements. sometimes it spreads well to micro-optimization territory.