- Single interface/trait:
- internal (C++-style dynamic dispatch)
- external (Rust-style wide ptr approach)
- Multi interface/trait:
- internal (C++-style dynamic dispatch)
- external (Rust-like approach)
- direct (merged vtables)
- indirect (pointers to interface/trait vtables in direct vtable)
- Contiguous - allocated objects' memory is contiguous and in order of their access
- Random - allocated objects' memory is completely random
- Contiguous + Type Sorted - allocated objects' memory is contiguous and their access order is based on their type (stable sorted by their type)
- Random + Type Sorted - allocated objects' memory is completely random and their access order is based on their type (stable sorted by their type)
Tests were performed under following configuration:
System: Windows 11 CPU: Intel i9-14900KF RAM: Kingston FURY Renegade 48GBx2 in Dual Channel and XMP Profile 1
Tests were measuring execution time of a method that accessed (added) values of the object and returned the value
Test size: 1000000
Count of different interface/trait implementations: 256
-
GCC (15.2.0):
- Single interface/trait:
AVG [ns] Contiguous Random Contiguous + Type Sorted Random + Type Sorted Internal VTable 8ns 7ns 1ns 4ns External VTable 8ns 7ns 1ns 4ns - Multiple interfaces/traits (A/B):
AVG (A/B) [ns] Contiguous Random Contiguous + Type Sorted Random + Type Sorted Internal VTable 9ns/8ns 8ns/8ns 1ns/1ns 6ns/5ns External VTable (direct) 7ns/7ns 7ns/7ns 1ns/1ns 4ns/3ns External VTable (indirect) 8ns/7ns 8ns/7ns 1ns/1ns 5ns/6ns -
MSVC (19.40.33821):
- Single interface/trait:
AVG [ns] Contiguous Random Contiguous + Type Sorted Random + Type Sorted Internal VTable 8ns 7ns 1ns 6ns External VTable 8ns 7ns 1ns 4ns - Multiple interfaces/traits (A/B):
AVG (A/B) [ns] Contiguous Random Contiguous + Type Sorted Random + Type Sorted Internal VTable 10ns/8ns 8ns/8ns 1ns/1ns 7ns/6ns External VTable (direct) 7ns/7ns 7ns/7ns 1ns/1ns 4ns/4ns External VTable (indirect) 8ns/8ns 7ns/7ns 1ns/1ns 5ns/4ns