
C++ for Games: Performance, Allocations and Data Locality - ingve
http://ithare.com/c-for-games-performance-allocations-and-data-locality/
======
trimbo
Mike Acton's "Data Oriented Design" talk from CppCon is great

[https://www.youtube.com/watch?v=rX0ItVEVjHc](https://www.youtube.com/watch?v=rX0ItVEVjHc)

~~~
cuckcuckspruce
Thanks for linking this talk. I've been wanting to get more into modern C++
after spending the last ten years in backend webapps in Perl/Python/PHP/Ruby.

~~~
lossolo
It's hardly modern C++ what you will see in this talk. Mike Acton even said
that they only use C++ because it's game industry standard but he would prefer
C. If you want to start with modern c++ watch this: CppCon 2015: Bjarne
Stroustrup “Writing Good C++14”

[https://www.youtube.com/watch?v=1OEu9C51K2A](https://www.youtube.com/watch?v=1OEu9C51K2A)

------
wmil
> use “++it” instead of “it++”

Has anyone actually benchmarked this recently? It's such a trivial
optimization for a modern compiler.

I have trouble believing that they'll produce different code when the return
value isn't used.

~~~
srean
Both are equally clear, and equally easy to type, so unless “++it” comes with
a drawback, I see nothing wrong with the suggestion. If the compiler is smart
it doesn't matter, if it isn't it will help.

Do you have anything particular against this suggestion ?

~~~
bottled_poe
This suggestion feels dogmatic. Instead, the suggestion should be to use a
better compiler.

~~~
Joof
If you only have 'platforms' compiler, then you have very little choice. I'd
guess it's becoming a smaller problem lately though; there's little reason to
use custom architecture.

------
Nican
I also recommend watching
[https://www.youtube.com/watch?v=Nsf2_Au6KxU](https://www.youtube.com/watch?v=Nsf2_Au6KxU)
, made by an engineer at Valve.

------
qopp
One comment: The “dragging a slider to the right” math is assuming all players
that pay $25/month are playing the entire month non-stop. In reality it goes
in waves. Using the "22.7 hours a week" from WoW, that's only 0.13/user/month.
Cloud computing capitalizes on this by renting per hour to capture the waves.
This means a 25$/month user is only costing $2.5 for server usage which seems
right.

------
lossolo
For anyone interested in optimizing C++ i recommend Agner blog.

[http://www.agner.org/optimize/optimizing_cpp.pdf](http://www.agner.org/optimize/optimizing_cpp.pdf)

EDIT: typo

------
bogomipz
Does anyone know who's behind this site/books? There's lots of great material
here. I always look forward to an update. Does anyone know if these books are
to be published?

~~~
signa11
some information is available here: [http://ithare.com/contents-of-
development-and-deployment-of-...](http://ithare.com/contents-of-development-
and-deployment-of-massively-multiplayer-games-from-social-games-to-mmofps-
with-stock-exchanges-in-between/#toc)

~~~
bogomipz
Not sure how I missed those, thanks for the link and the link to the
kickstarter, I would like to support this book. Cheers.

------
tfigment
I found this to be fairly interesting content. I knew most of it so useful as
a refresher and one can really argue not game specific in many ways though
certainly slanted in that direction. Anything with real-time performance
considerations like control/embedded system programming can also use the
advise. I found Alexandresu's Modern C++ Design valuable many years ago for
similar advise. I used Loki and its allocators and smart pointer strategies in
a lot of code over the years due to control over data locality.

I found the next posts/chapters on Marshalling and Encoding even more
interesting with comparison and pros/cons of different encoding techniques. I
was not aware of the FlatBuffers library and see why the author likes it and
may have to look into using in future projects.

------
partycoder
I prefer this explanation from Herb Sutter, member of the ISO C++ committee:
[https://youtu.be/TJHgp1ugKGM?t=21m33s](https://youtu.be/TJHgp1ugKGM?t=21m33s)

------
shmerl
Thanks, very interesting reading. It can be valuable not just for games
development but for any case when performance is important.

~~~
Matthias247
That applies to most of the information on this website and in the upcoming
book. It's labeled as for Game Development, but most things also apply to
network programming in general (e.g. implementing RPC systems, message
brokers, protocols like HTTP, ...). It's a great resource!

------
nice_byte
Small question, I don't really see how switching to unordered_map solves the
locality problem that the author mentioned... unordered_map most likely uses
chaining, and even if we were allocate a continuous block of memory for each
bucket (as opposed to having a linked list), we'd still have a locality issue.

~~~
santaclaus
I think C++'s built in unordered_map has to use chaining due to restrictions
on iterators mandated for standard library containers, which is a drag. You've
still got to roll your own open addressed container. :( This comes up in one
of Chandler Carruth's talks [1].

[1]
[https://www.youtube.com/watch?v=fHNmRkzxHWs](https://www.youtube.com/watch?v=fHNmRkzxHWs)

~~~
nice_byte
Yep, that's exactly what I did (because of the same concerns) in one of my
projects, which is why I was initially surprised to see them recommend
unordered_map. But, as the other commenter pointed out, unordered_map has way
less "hops" and thus provides a _significant_ improvement over a search tree
in terms of locality.

