понедельник, 3 марта 2008 г.

Еще раз о производительности STL

В принципе вопрос можно считать закрытым...
Electronic Arts Standard Template Library
описание собственной версии STL используемой в Electonic Arts, описание причин ее возникновения, проблем с текущей реализацией STL с точки зрения gane developming, да и вообще много много интересного.

Навскидку:
A common high-performance technique is to create a temporary hash table with a fixed-size memory buffer, do processing with it, and then "nuke" the hash table when done instead of going through the process of clearing and deallocating its nodes.

EASTL explicitly supports this programming pattern via the reset function. The supplied allocator generally must cooperate with this, lest memory leaks occur. However, it can work safely only with value types that have a trivial destructor.

People have been recommending the "swap trick" for years, but this is an obfuscated and easy-to-forget workaround in place of what should be built-in functionality. If a workaround is well-known enough that there are hundreds of pages on the Internet devoted to it and it has its own nickname, it probably should be built into the standard library. set_capacity is the same thing as resize_capacity which has been suggested by some.

Existing std STL implementations implement insertion operations by copying from an element. For example, resize(size() + 1) creates a throw-away temporary object. There is no way in existing std STL implementations to add an element to a container without implicitly or explicitly providing one to copy from (aside from some existing POD optimizations). For expensive-to-construct objects this creates a potentially serious performance problem. A typical suggested workaround to this problem with std STL is to store pointers instead of objects; however, such external memory allocation is undesirable for reasons described elsewhere in this document.

list and deque have both push_back(void) and push_front(void). slist has push_front(void). map, multimap, hash_map, and hash_multimap have insert(key). insert(key) is the same thing as the lazy_insert function that has been suggested by some. Other related proposals have been put forward.


Вообщем читать и плакать. Я в принципе понимаю всю сложность работы по стандартизации языка и стандартных библиотек...но иногда...иногда мне кажется что в комитете по стандартизации С++ сидят злые гении, цель которых - убить С++.

Еще интересная ссылка - Technical Report on C++ Performance

Комментариев нет: