EASTL (Electronic Arts Standard Template Library)
repository·master·Indexed 27 days ago
https://github.com/electronicarts/eastlA high-performance C++ template library of containers, algorithms, and iterators developed by Electronic Arts. Designed for use in tools and shipping applications across platforms ranging from embedded systems to servers, EASTL provides specialized options such as intrusive containers, fixed-size containers, and vector_map to optimize memory usage and performance.
What's inside EASTL
- EASTL (Electronic Arts Standard Template Library) is a C++ template library providing containers, algorithms, and iterators. It is designed for high performance and is suitable for runtime and tool development across multiple platforms, ranging from embedded systems to servers and mainframes.
Overview of EASTL Modules
masterEASTL is composed of several top-level modules providing standard template library functionality. These include containers (lists, vectors, maps, sets), algorithms (sorting, searching, numeric), and utilities (smart pointers, type traits, iterators).
Note: For complex modules like
algorithm, which contains many submodules, consult the source code or specific module documentation for detailed information.Understand EASTL benchmark results
masterEASTL provides benchmark results to compare its performance against other standard libraries (like Microsoft Dinkumware or STLPort).
Key details regarding the benchmarks:
- Debug Performance: EASTL includes specific optimizations to enhance debug performance. In some cases, it can be 10x or more faster than alternatives, though there are exceptions where it may be slower.
- Metric: Values represent the time taken to complete tests; smaller values are better.
- Alarm: An asterisk (
*) in the 'Alarm' column indicates a difference greater than 10% between the tested libraries. - Submission: Developers are encouraged to submit results for additional compilers or platforms.
Understand EASTL Container Categories
masterEASTL containers are categorized based on how they store and access elements:
- Sequence Containers: Variable-sized containers with elements in a strict linear order. Examples include
vector,deque,array,list, andslist. - Associative Containers: Variable-sized containers that support efficient retrieval based on keys. They support insertion and removal but do not provide positional insertion. Examples include
map,multimap,set,multiset,hash_map,hash_multimap,hash_set, andhash_multiset. - Adapters: Containers that provide a specific interface by wrapping another container. Examples include
stack(LIFO),queue(FIFO), andpriority_queue(heap-based). - Intrusive Containers: Containers that do not allocate separate memory for nodes but instead use pointers embedded within the contained objects themselves (e.g.,
intrusive_list,intrusive_hash_map).
- Sequence Containers: Variable-sized containers with elements in a strict linear order. Examples include
Understand EASTL Design Principles
masterEASTL (EA Standard Template Library) is optimized for game development, prioritizing Efficiency (speed and memory usage) over academic correctness.
Key design differences from standard STL include:
- A simplified and more flexible custom allocation scheme.
- Optimizations for game development (e.g., avoiding memory allocation for empty containers).
- Support for object alignment.
- Extension containers and algorithms (e.g.,
slist,intrusive_list). - Improved readability and shallower function call stacks.
Note on Portability: While EASTL is designed to run on all target platforms, it may not support every compiler (e.g., it may not work with very old compilers like Microsoft VC6 due to weak C++ support).
Understand EASTL benchmark results and performance trade-offs
masterEASTL benchmarks are designed to compare EASTL functionality against equivalent implementations in other libraries (like compiler STL libraries). When interpreting results, consider the following:
- Platform Sensitivity: Performance results are highly dependent on the hardware. Modern PCs with large caches and branch prediction will show different results compared to embedded or console systems.
- Design Trade-offs: EASTL may perform slower than
std STLin specific benchmarks because it prioritizes speed, memory, or design optimizations for other, more critical use cases. This accounts for the majority of performance differences. - Compiler Optimizations: Differences in performance can sometimes be attributed to how specific compilers optimize code generation for one implementation over another.
- Optimization Maturity: While EASTL generally outperforms
std STL, there may be rare instances where it is less optimized.
Understand EASTL Design Principles and Prime Directives
masterEASTL is designed with a specific hierarchy of priorities that guide all implementation decisions. When contributing or extending the library, follow these directives in order of importance:
- Efficiency: Prioritize speed and memory usage. Note that some functionality may have usage limitations compared to standard STL to achieve higher efficiency on target platforms.
- Correctness: Ensure the code is bug-free.
- Portability: The code must work on all required platforms with minimal specialized code.
- Readability: Code should be legible with useful comments.
Unlike many commercial STL implementations, EASTL prioritizes Efficiency over absolute correctness in certain edge cases to optimize for performance.
EASTL Best Practices Summary
masterThis document provides a list of performance-oriented best practices for using the EA Standard Template Library (EASTL). The primary focus is on performance, followed by correctness and maintainability. The practices are categorized into container selection, memory management, and algorithmic efficiency.Implement comparison operators for structs with multiple members
masterWhen implementing
operator<for a struct with multiple members, you must ensure a strict weak ordering. You can achieve this by checking members sequentially: if the first members are unequal, return their comparison; otherwise, proceed to the next member.struct X { Blah m1; Blah m2; }; bool operator<(const X& a, const X& b) { return (a.m1 == b.m1) ? (a.m2 < b.m2) : (a.m1 < b.m1); }Use EASTL algorithms and iterators
masterEASTL algorithms follow the standard C++ philosophy of operating on iterators rather than containers. This allows you to:
- Specify subranges within a container.
- Apply algorithms to non-container sequences, such as C-style arrays.
Algorithms are highly optimized using type traits. For example, resizing an array of POD (Plain Old Data) types will trigger a
memcpyinstead of an element-by-element move.Determine when to use operator< vs operator==
masterThe requirement for specific operators depends on the container or algorithm being used:
- Sorted Containers (like
setormap): Typically requireoperator<to establish ordering. - Unordered Containers/Search Algorithms: Typically require
operator==to check for equality.
- Sorted Containers (like
Avoid subclassing EASTL containers
masterEASTL containers are not designed for arbitrary subclassing for performance reasons (to avoid virtual functions). Subclassing can lead to unpredictable behavior if a parent class function calls a method you intended to override but cannot see. If you must subclass, use it strictly as a wrapper for the container.