DEV Community

Taqmuraz
Taqmuraz

Posted on

C++ : speed obsession in the game industry

When do we really need speed

C++ became a standard language for games and graphics software a long time ago. And, there was actual reason -- work with real-time graphics and physics requires high performance. Processing geometry, managing buffers, matrix calculations - all of that does take time.
But, what about high-level logic? Game mechanics, user interface, storage management, network requests? Stability and safety are much more demanded there, than speed.

Responsibility distribution

We may implement performance-demanding functions in a compiled language, such as C++, and call them from a program written in a dynamic language, such as Python.
But, today we already have well-documented and easy to use libraries for Python (pygame, pyopengl, pyassimp, pybullet, numpy), that are implemented primarily on C/C++ and do provide functions for heavy calculations, or physics/graphics in particular. We may never face necessity to implement such libraries on our own.

Is C++ the only choice?

It is generally accepted, that garbage collected languages, such as Java or C#, are slower than C++ and don't really meet requirements for heavy calculations. This is, of course, not true.
C++ may overcome Java or C# in performance by 20-30% in some special cases, but when it comes to runtime abstractions, such as dynamic function dispatch, languages interaction, asynchronous tasks, text or abstract collections management, Java and C# show much higher efficiency than C++.
Also, we may run our Python programs on the same runtime with Java or C#, using Jython or IronPython. It brings a lot of benefits, such as shared garbage-collected memory, types system and easy access to C# or Java libraries right out of the box. On Java are implemented such nice dynamic languages as Clojure and Groovy, that have complete access to Java Class Library and share previously mentioned benefits.

What really makes influence on performance?

Today personal computers are much faster, than 15-20 years ago. But, most of desktop programs or games do not work as fast as expected (despite that they are still mostly implemented on C/C++). Today we need good algorithms and effective approaches much more, than just language speed. Function with constant complexity on Python is more preferable than function with linear complexity on C. To paint 100 trees by 15 lines of Python code is more preferable than to paint 500 trees by 300 lines of C++ code.

Care about game, not language

It is not really important, what language you use, when you don't have any game made, right?
Making game on C++ is much more demanding and exhausting, than doing same on Python or Ruby. When you would make 1 game with C++, you would make 10 games with Python. When you would make 5 games with Python, it would be 0 games with C++.
Let us care about games and fun, otherwise what the point?

Top comments (3)

Collapse
 
fst2000 profile image
Sergey

As a game developer, I can say that this is absolutely true. Games are written very easily in python, unlike C and C++, because while you're messing with optimization and debugging in C++, you're just writing game logic in python.
And the code looks much more readable and beautiful in dynamic languages.

Collapse
 
evgenijshelukhin profile image
evgenijShelukhin

What about GC, doesn't it cause lags and freezes?

Collapse
 
taqmuraz profile image
Taqmuraz

Usually GC is so fast that you can't even recognize it. Normally garbage collection takes less than 0.5% of the frame time