Fast and small C++ - When efficiency matters - Andreas Fertig - Meeting C++ 2024
Вставка
- Опубліковано 17 січ 2025
- Fast and small C++ - When efficiency matters - Andreas Fertig - Meeting C++ 2024
Slides: slides.meeting...
Survey: survey.meeting...
C++ is well known to be used, especially when efficiency matters and you want complete control of the resulting binary.
In this talk, you will learn about tricks the Standard Template Library uses to keep data storage size small. Are you familiar with Small String Optimization? Brace yourself for uncovering yet another ingenious strategy that might surprise you.
Everybody, including me, tells you how great `constexpr` is, but do you truly believe its potential? Embark on a journey with me as we delve into a compelling example demonstrating the transformative impact of constexpr, which enhances runtime performance while reducing memory overhead.
Furthermore, I'll unveil C++ Insights' capabilities and demonstrate how it can assist your approach to designing class data member layouts, ultimately optimizing the size of your data types.
Are you leveraging uniform initialization for your data types? Let's delve into the implications, especially when initialization necessitates a std::initializer_list. C++23 has an interesting change that might help you.
I am confident that this session will equip you with invaluable insights and practical techniques that can be readily applied to improve your codebase.
P.S: You miss lambdas from the description? Well, I promise I will show you a C++23 improvement to lambdas.
*Fast and Small C++: When Efficiency Matters*
* *0:00:10** Introduction:* The talk focuses on achieving both speed and small size in C++, particularly in resource-constrained environments like embedded systems.
* *0:01:31** Personal Introduction:* The speaker introduces himself as Andreas Fertig, a C++ trainer, consultant, author of books on C++, and developer of the C++ Insights tool.
* *0:04:07** Unique Pointer Optimization:* Discusses how `std::unique_ptr` can be customized with deleters to manage resources other than dynamically allocated memory, such as file handles.
* *0:07:52** Empty Base Class Optimization (EBCO):* Explains how EBCO is used within `std::unique_ptr` to avoid storing an extra pointer when a custom deleter is stateless, thus saving space.
* *0:14:23** No Unique Address Attribute:* Introduces the C++20 `[[no_unique_address]]` attribute as a way to achieve similar space savings to EBCO without inheritance, simplifying the implementation of compressed pairs.
* *0:15:35** Compressed Pair in `std::unique_ptr`:* Shows how `std::unique_ptr` utilizes a compressed pair to store both the managed pointer and the deleter efficiently.
* *0:18:49** Small String Optimization (SSO):* Explores how `std::string` implementations often employ SSO to avoid dynamic allocation for short strings by storing them within the string object itself.
* *0:24:16** SSO Implementations:* Compares SSO strategies in different standard library implementations (libstdc++, libc++, MSVC STL), highlighting their trade-offs in terms of payload size and branch overhead.
* *0:37:25** Facebook's `fbstring`:* Presents Facebook's `fbstring` as an example of a highly optimized string implementation that achieves a larger SSO capacity (23 bytes) by cleverly encoding mode and length information.
* *0:40:17** `constxpr` and RAM Savings:* Demonstrates how using `constexpr` with a custom `FixString` class can significantly reduce RAM usage by allowing string literals to reside solely in ROM, avoiding runtime copying to the stack.
* *0:47:51** `std::initializer_list` and Defect Report:* Discusses a defect report that allows compilers to optimize `std::initializer_list` backing arrays as if they were `static` in certain cases, leading to further code size reductions.
* *0:55:49** Conclusion:* Emphasizes the importance of understanding these optimization techniques for writing efficient C++ code, especially in memory-constrained environments.
* *0:56:21** Q\&A:* The speaker answers several questions about the topics presented, including the application of these techniques to other data structures like `std::vector` and the use of bit fields and unions in standard library implementations.
I used gemini-1.5-pro-exp-0827 on rocketrecap dot com to summarize the transcript.
Cost (if I didn't use the free tier): $0.08
Input tokens: 64909
Output tokens: 647
For anyone getting tired of hearing about his name, start from 4:00 , the rest seems insightful.
Hahaha, in every video!
thank you!