Repository navigation
Description
From the "FBVector.md" page I would like to add more comment then an "issue".
Now since the focus is on "performance" a few key things need to be pointed out about "std::vector"
or any similar implementation. For that matter any kind of memory container.
To get real performance out of any program you need to know what is going on "under the hood".
At least for key parts like an STL containers.
Programmers of any language just thinking in terms of high level abstractions, thinking in ways of just
"this is how it' done", this is what my teacher, or my CS text book says, etc., just dropping things here and there
are never really going to get real performance unless it happens by accident.
Not to mention suffer from other evils like code bloat to some degree or another.
Performance is particularly important for real time applications like games, simulations, etc.
And really wouldn't we all like better performing day to day applications and tools that we use all the time?
Read Pete Isensee articles where he breaks down a lot of STL use in game development.
His Game Programming Gems chapters and GameDev articles, etc., like "Common C++ Performance Mistakes in Games".
You can get most of it free with source code on his site: www tantalon com
The key points with vectors:
-
Use ".reserve()" when you know how many exact or maximum elements you need.
No performance hit for growing an array when there isn't.
Note also at least with a Windows OS and it's paging mechanism that physical RAM pages are not actually until they touched. So you can ".reserve()" a bit more then you need without issue. -
Use "resize()" vrs "clear()" to reset element count to zero. "clear()" will cause the vector allocation to free (and thus need to be re-allocated again) where "resize()" doesn't.
-
For CPUs where it matters (read all modern day PC CPUs) make things cache aligned when possible.
If you can (allocations are not to too large, etc.) use align 16 containers.
Then use a custom STL Allocator that provides align 16 blocks. Easier then you think, use Pete's source code and read the articles.
Also a good on the subject is "Data-Oriented Design (Or Why You Might Be Shooting Yourself in The Foot With OOP)" by
Noel Llopis, et al.
Activity
tudor commentedon Aug 23, 2012
Thanks for the comment. I'll be closing this issue because the issue tracker is meant for specific problems with the code.
Switch uses of networking headers to <folly/portability/Sockets.h>
avoid UB in StringKeyedCommon for default constructed StringPiece
fix unsigned-integer-overflow
fix misaligned-pointer-use in StlVectorTest
Zero size array causes crash in AsyncUDPSocket on llvm15
folly: io_uring: only call readCallback if it did not change
replace typeid-comparison crash on macOS in StaticSingletonManagerWit…