Updated to C++20 with completely revised code and more content on error handling, benchmarking, memory allocators, and concurrent programming
Explore the latest C++20 features including concepts, ranges, and coroutines
Utilize C++ constructs and techniques to carry out effective data structure optimization and memory management
Description
C++ High Performance, Second Edition guides you through optimizing the performance of your C++ apps. This allows them to run faster and consume fewer resources on the device they're running on without compromising the readability of your codebase.
The book begins by introducing the C++ language and some of its modern concepts in brief. Once you are familiar with the fundamentals, you will be ready to measure, identify, and eradicate bottlenecks in your C++ codebase. By following this process, you will gradually improve your style of writing code. The book then explores data structure optimization, memory management, and how it can be used efficiently concerning CPU caches.
After laying the foundation, the book trains you to leverage algorithms, ranges, and containers from the standard library to achieve faster execution, write readable code, and use customized iterators. It provides hands-on examples of C++ metaprogramming, coroutines, reflection to reduce boilerplate code, proxy objects to perform optimizations under the hood, concurrent programming, and lock-free data structures. The book concludes with an overview of parallel algorithms.
By the end of this book, you will have the ability to use every tool as needed to boost the efficiency of your C++ projects.
Who is this book for?
If you're a C++ developer looking to improve the efficiency of your code or just keen to upgrade your skills to the next level, this book is for you.
What you will learn
Write specialized data structures for performance-critical code
Use modern metaprogramming techniques to reduce runtime calculations
Achieve efficient memory management using custom memory allocators
Reduce boilerplate code using reflection techniques
Reap the benefits of lock-free concurrent programming
Gain insights into subtle optimizations used by standard library algorithms
Compose algorithms using ranges library
Develop the ability to apply metaprogramming aspects such as constexpr, constraints, and concepts
Implement lazy generators and asynchronous tasks using C++20 coroutines
Very nice book full of insights on the use of modern c++ for efficient coding. Nicely written an plenty of examples.
Feefo Verified review
Amazon CustomerFeb 22, 2021
5
I was excited to see how this book covers C++; it has an emphasis on "high performance" and assumes familiarity with C++, and computer systems in general. It dives right into techniques to optimize C++ code, from data structures to memory management to concurrency and more, with lots of code examples to demonstrate concepts. I really liked how the book got close to low-level constructs, such as operating systems and assembly, so that the user could more fully understand what the C++ code was doing. If you haven't worked with C++ before then this might be a dense read. In my opinion, C++ is a pretty complex language and there's lots to unearth, and this book is all about understanding the intricacies of the language. If you want to expand your understanding of C++ and optimize your code through various means, then I think this book does a great job of showing how to do so!
Amazon Verified review
shukailinFeb 17, 2021
5
This book contains several topics including selected algorithm and data structure from STL, memory management, features of C++17 and 20, concurrency, template and more. In some topics, it not only introduces the features but also explain down to machine level so that the reader can get full background on why it has to be done in this way comparing with the other ways. It also mentions several useful tips for essential techniques in C++ which is quite common and useful when doing code review. The book also recommends readers to use https://godbolt.org/ which is a great tool to evaluate performance of different implementation. Also, one can find all the code used in the book on github which is a big plus since readers can easily evaluate it by themselves. I highly recommend this book to the C++ developer who has 2-3 years experience in C++!
Amazon Verified review
hawkinflightJan 13, 2021
5
I recently needed to interact with a C++ code base, and to come up to speed rapidly. Now, after having done that, I am looking at this book to add to what I learned. This is a very solid book. I am very happy that its goal is to focus on how to use the modern version of the language, C++20. There is a lot of material here, and it is thoughtfully and clearly presented.The first three chapters are very inviting and address topics of interest to me:Ch 1) Brief Introduction to C++ - answers "why C++?" and identifies features and drawbacks of the language, as well as the advantages and disadvantages as compared to other languagesCh 2) Essential C++ Techniques - presents modern and essential features of C++, features that one should know to use today's version of the languageCh 3) Analyzing and Measuring Performance - provides excellent material on comparing the efficiency of algorithms and data structures, also covers how to quantify performance by measuring latency and throughput, as well as how to identify hot spots using CPU profilers and how to improve isolated parts of the code by performing microbenchmarkings.The authors indicate that the remaining 11 chapters can be read independently. All of these remaining chapters look good to me, and the next four chapters cover basics which I don't want to skip:Ch 4) Data Structures - emphasizes checking the asymptotic complexity when choosing a data structure, and the importance of the cache level hierarchy in processors, and how it impacts how we need to organize the data for efficient memory accessCh 5) Algorithms - teaches how to use the basic concepts in the Algorithms library, and the advantages of using that library instead of handwriting for-loopsCh 6) Ranges and Views - presents using Range views to construct algorithms. "By using views, we can compose algorithms efficiently, and with a succinct syntax, using the pipe operator." A class can be a view and range adapters can be used to turn ranges into views.Ch 7) Memory Management - emphasizes the importance of understanding how your program uses memory, and advises that if you're facing memory issues, it's a good idea to check what's already available in libraries, since building custom memory managers that are fast, robust, and safe is a challenge. It is mentioned that "what you need" likely already exists, that someone else has probably had the same issue.Some interesting features of the last 7 chapters in the book are:Ch 8) Compile-time programming: demonstrates modern C++ techniques. By using templates, the constexpr, static_assert(), and if constexpr, type traits, and concepts to use metaprogramming to generate functions and values at compile time instead of runtime.Ch 9) Essential Utilities: combines essential classes from the C++ Utility library with containers and metaprogramming to store and iterate over elements of different types, as well as presents an example of implementing reflection, which is not built into C++, though it is planned to be included in future versions of the C++ standard, possibly in C++23.Ch 10) Proxy Objects and Lazy Evaluation - shows how to postpone the execution of certain code until required. Proxy objects can be used to leave exposed interfaces intact and enable optimizations to occur under the hood.Ch 11) Concurrency - provides an introduction to the C++ thread support library, the atomic library, andthe C++ memory model, a short example of lock-free programming, and performance guidelines, including advice on achieving low latency and high throughput. C++20 comes with some useful synchronization primitives: latches, barriers, and semaphore.Ch 12) Coroutines and Lazy Generators - the coroutines added to C++20 are stackless coroutines, though stackful coroutines can be used via third-party libraries. Stackless coroutines are closely related to state machines. A generator is a type of coroutine that yields values back to its caller, and are a way to build lazily evaluated sequences. An example demonstrates how to use C++ coroutines for building generators using the keywords co_yield and co_return.Ch 13) Asynchronous Programming with Coroutines - gives an introduction to the novel feature of asynchronouscoroutines in C++, and introduces a methodology called structured concurrency. It is noted that "although asynchronous programming is the most important driver for having coroutines in C++, there is no support forasynchronous tasks based on coroutines in the standard library", and it is recommended that a library that complements C++20 be used, such as CppCoro or Boost.Asio.Ch 14) Parallel Algorithms - are a way to speed up concurrent programs by utilizing multiple cores. Parallel execution of independent tasks is related to but distinct from concurrency. The parallelism should be abstracted away so that parallelizing code is only a matter of changing a parameter to an algorithm. The importance of parallelism and how to evaluate parallel algorithms is covered.Valuable final comments are provided about performance and the current compiler status for C++20:1) Performance - is an "important aspect of code quality. But too often, performance comes at the expense ofother quality aspects, such as readability, maintainability, and correctness. Solving performance problems usually comes down to a willingness to investigate things further. More often than not, it requires understanding the hardware and underlying OS well enough to be able to draw conclusions from measurement data."2) C++20 compiler support - one of the authors indicates that "a lot of the code presented in this book is only partially supported by the compilers today. I will keep updating the GitHub repository and adding information about compiler support."Really nice book.
Amazon Verified review
Wil COct 25, 2023
5
Written at the right level of depth (not for beginners). Emphasizes modern idioms (C++20). Balanced, thoughtful advice. The comparative language analysis aids in compensation and helps weigh tradeoffs.
Björn Andrist is a freelance software consultant currently focusing on audio applications. For more than 15 years, he has been working professionally with C++ in projects ranging from UNIX server applications to real-time audio applications on desktop and mobile. In the past, he has also taught courses in algorithms and data structures, concurrent programming, and programming methodologies. Björn holds a BS in computer engineering and an MS in computer science from KTH Royal Institute of Technology.
Viktor Sehr is the founder and main developer of the small game studio Toppluva AB. At Toppluva he develops a custom graphics engine which powers the open-world skiing game Grand Mountain Adventure. He has 13 years of professional experience using C++, with real-time graphics, audio, and architectural design as his focus areas. Through his career, he has developed medical visualization software at Mentice and Raysearch Laboratories as well as real-time audio applications at Propellerhead Software. Viktor holds an M.S. in media science from Linköping University.
A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content
How can I cancel my subscription?
To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.
What are credits?
Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.
What happens if an Early Access Course is cancelled?
Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.
Where can I send feedback about an Early Access title?
If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team.
Can I download the code files for Early Access titles?
We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.
When we publish the book, the code files will also be available to download from the Packt website.
How accurate is the publication date?
The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.
How will I know when new chapters are ready?
We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.
I am a Packt subscriber, do I get Early Access?
Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.
How is Early Access delivered?
Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.
How do I buy Early Access content?
Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.
What is Early Access?
Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.