Hi,Getting back to the original post:
Just out of curiosity, I heard that game engine is mostly written in C++ because it is faster. But I don't know what kind of optimization C++ can offer over C#, can someone give some highlights so I can have general ideas of it
The myth that C# is inherently slower than C++ is exactly that: a myth.
There are similar myths that Java was inherently slower than C++, and they are also a myth.
Early compilers in both languages were very pessimistic in optimization and did generate slower binaries. Those very early tools have evolved.
There are facets of the libraries that are faster, and facets of the libraries that are slower. But the languages themselves are equal.
C++ is the core language in large part because experienced programmers know c++ and know how to get solid performance out of it. When engines must be cross-platform it is currently easier to use c++ because the third-party vendors provide c++ based interfaces; the network effect has locked that language in power for the time being. That is changing rapidly as many third party vendors are clearly moving toward C# as their preferred interface.
When you take an experienced c++ programmer and try to turn them into competent Java or C# programmers, there is a clear learning curve as they must re-learn what patterns are expensive to use and which are cheap.
It is easy to write poor-performing c# code if you are not familiar with the language, and most experienced game engine developers are not very fluent in c#. It is difficult for those experienced developers to make the transition.
Many of the up-and-coming developers are able to write more high quality code in C# than the experienced C++ developers could do in C++. Few developers need to know raw assembly any more because there are more productive tools out there. My studio has been mostly in C# for six years now, and the difference between our c++ and C# code is incredible. There was a brief learning curve and migration cost, but it has been more than made up for by performance in creating games. It is easier to put more in the game, and our results are at least as good. It is easier to find skilled C# programmers who can write performance-critical code than it is to find C++ developers who can do the same.
There is very clear motion in the works. From my perspective nearly all our tools are written in C#, and a good portion of our engine and most of our game code is written in C#. Mono runs great on all the major consoles, and there is no need for JIT compilation since the tools can emit the fully-optimized binaries if you pass the right arguments.
The OP (and many others) have just made the assumption that C# is slower or more cumbersome. I heard the same thing in the 90s that C++ was bloated and more cumbersome than C. I read the same arguments in the 80's that C was painfully slow and could never replace the skilled assembly-writing artisan.
The question has never been "will c++ be replaced", but "when". I believe we passed the tipping point a few years ago. It is now more difficult to get a seasoned C++ developer than to get a seasoned C# developer who is also more productive overall than that c++ developer.