Black Friday Deals For Authors Are On Now!

Leanpub Header

Skip to main content

Production C++ Engineering

Bought separately

$158.98

Minimum price

$79.00

$139

You pay

Author earns

$

Also available for 3 book credits with a Reader Membership

These books have a total suggested price of $158.98. Get them now for only $79.00!
About

About

About the Bundle

Books

About the Books

Production CMake for C++ Engineers

Production CMake for C++ Engineers

Fixing Dependency Hell and Slow Builds with Modern Targets, Presets and Modules

Your build shouldn’t be the slowest, least understood part of your system.

Most C++ engineers never chose to learn CMake. They inherited a CMakeLists.txt, copied a block to add a dependency, and moved on. Then the clean build hits half an hour, a dependency upgrade breaks three teams, and the release binary behaves differently from the one that passed CI.

This book is for that moment. It isn’t a beginner’s tour of CMake commands. It’s a field manual for fixing real production builds. Every chapter opens with a real-world failure: a version endpoint reporting the wrong commit, two copies of a library in one binary, a CI pipeline that broke without a single commit. Each one is traced back to its cause, and the fix is one you can apply, verify, and keep.

What you’ll learn:

  • How CMake actually works: configure, generate, and build phases, the cache, scope rules, and the policy system
  • Target-based CMake done properly, with PUBLIC, PRIVATE, and INTERFACE usage requirements and no leaked flags
  • Presets and toolchain files that make a build depend on the repository, not on the machine running it
  • Consuming dependencies with find_package, FetchContent, vcpkg, and Conan, and using dependency providers to control all of them from one place
  • Fixing dependency hell: diamond dependencies, ODR violations, version conflicts, and old dependencies that stop configuring on CMake 4
  • Producing relocatable packages others can consume, plus Python wheels built from the same project with nanobind and scikit-build-core
  • Faster builds with Ninja, ccache, precompiled headers, and unity builds, and diagnosing slow builds with -ftime-trace, build timelines, and faster linkers
  • C++20 modules and import std in CMake, including a migration path for existing codebases
  • Cross-compiling for ARM, embedded, Android, iOS, WebAssembly, and Apple universal binaries, plus CUDA as a first-class language
  • Testing and code quality: CTest, sanitizers, coverage, clang-tidy, libFuzzer targets, and SARIF annotations on pull requests
  • Production concerns: CI caching, reproducible builds, CPack, SBOMs, license tracking, and code signing
  • CMake at scale: monorepos, superbuilds, debugging CMake itself, and migrating from legacy builds

Every chapter ends with a Build Health Ledger, a measured record of what changed in configure time, clean build time, incremental rebuild time, and which problems were removed, along with how each fix was verified. Appendix D gathers every check into one build health checklist you can run against any codebase.

Who it’s for: C++ engineers who already use CMake and want to use it well, and anyone who has just been handed a team’s build and told to make it faster and stop it breaking.

Requirements: CMake 3.28 or later. Features from newer releases, including CMake 4.x, are marked by version.

Bare-Metal Performance Engineering in C++

Bare-Metal Performance Engineering in C++

Profiling with perf and Top-Down Microarchitecture Analysis to Build Benchmarks That Don’t Lie

Your benchmark says 4x faster and production doesn’t move. This book is about why, and how to make your numbers tell the truth.

Most C++ performance advice is folklore: virtual calls are slow, exceptions are free, -O3 beats -O2, more threads means more throughput. Each of these is true on some hardware, for some workloads, some of the time, and teams lose weeks acting on them without measuring. Meanwhile the real costs go unseen: a compiler that quietly deleted the code being benchmarked, a profiler that blamed the instruction after the one that missed cache, a hash table that waits on DRAM twice per lookup, a load test that misses the stalls production clients hit.

Bare-Metal Performance Engineering in C++ teaches the discipline that replaces guesswork with evidence. You’ll learn to write benchmarks the compiler can’t fool, to read hardware counters without being misled by multiplexing or skid, and to use Top-Down Microarchitecture Analysis to find in one run whether code is starved in the front end, losing work to mispredictions, or stalled on memory. Then you’ll apply that method from the compiler out to the kernel, and keep the results in place in production.

The book follows a single realistic workload from start to finish: a request-handling service that parses JSON, looks keys up in a multi-million-entry hash table, and serializes responses. Every chapter ends with a Bottleneck Ledger entry recording the service’s cycles per request, IPC, cache misses, and latency percentiles, the dominant bottleneck at that stage, what changed, and how the change was verified. By the end, the service uses about a third to a quarter of the CPU per request it started with, with a fraction of its original tail latency, and every step of that improvement is shown and justified.

What you’ll learn
  • How microbenchmarks lie through dead code elimination, constant folding, and hoisting, and how to prove they don’t with assembly and statistics
  • How to control frequency scaling, turbo, SMT, and core isolation so that a 2 percent difference means something
  • How the front end, out-of-order back end, branch predictor, SIMD units, caches, TLBs, and NUMA actually determine your code’s speed, with differences across Intel, AMD, and Arm called out
  • How to use perf stat, perf record, precise events, call graphs, flame graphs, and differential profiles correctly
  • How to diagnose bottlenecks with Top-Down analysis using perf, toplev, and VTune
  • How to read x86-64 and ARM64 compiler output well enough to spot missed vectorization, spills, bounds checks, and hidden calls
  • How to find time spent waiting rather than computing, using off-CPU profiling, eBPF, Perfetto, LTTng, and Intel Processor Trace
  • How to get the most from the compiler with LTO, PGO, AutoFDO, BOLT, and optimization remarks
  • What C++ abstractions really cost under measurement: virtual dispatch, exceptions, std::function, and template bloat
  • How to apply data layout, allocation, container, branchless, SIMD, and loop-transformation techniques, each shown as a measured before-and-after pair
  • How to scale concurrency: diagnose false sharing, coherence traffic, and lock contention, and choose between locks, sharding, and lock-free snapshots
  • How to tune at the system level: system call costs, page faults, io_uring, interrupt affinity, and transparent huge pages
  • How to keep it fast with HDR histograms, open-loop load testing, continuous profiling, and regression gates in CI
Who this book is for

This book is for C++ engineers who own the performance of code that runs in production: backend and infrastructure engineers with latency objectives, library maintainers, low-latency and trading developers, and anyone who reviews pull requests that claim speedups. It assumes you’re comfortable with modern C++ and basic computer architecture terms like caches and pipelines. It doesn’t assume prior experience with perf, assembly, or Top-Down analysis, because each tool is introduced from first principles where it’s needed.

It isn’t an algorithms book. It covers what happens after you’ve chosen the right algorithm, when two implementations of it differ by a factor of five because of how they use the machine.

What makes it different
  • Measurement first. Every performance claim is either measured with the method shown or framed as something you must measure. Figures are given as realistic ranges, not invented benchmark results.
  • Real code. The listings are complete, modern C++20/23 and are meant to compile, with the error handling real benchmarks and profiling harnesses need. Assembly listings state the compiler, version, and flags.
  • Hardware-aware. Claims name the microarchitecture they apply to, and the book points out where Intel, AMD, and Arm cores behave differently.
  • Trade-offs stated up front. Every technique comes with its costs: code size, memory, semantics, portability.
  • Production-ready. The final part covers tail-latency measurement, continuous profiling, CI regression detection, and a step-by-step investigation runbook.
What you need
  • A Linux machine, either x86-64 or AArch64, ideally bare metal, since many cloud VMs expose few or no hardware counters
  • GCC 13 or newer, or Clang 17 or newer
  • CMake and Google Benchmark
  • perf

VTune, AMD uProf, bpftrace, and Perfetto are used in later chapters. Four appendices give quick references for perf, hardware events and Top-Down metrics, compiler flags, and a full benchmarking and profiling checklist.

Memory-Safe C++ in Production

Memory-Safe C++ in Production

Enforcing Bounds and Lifetime Safety Through Hardened Libraries and Sanitizer-Driven Development

Most of a large C++ codebase's serious security bugs come from a short list of failures: an index one past the end, a reference kept after its object is gone, a cast that trusts the wrong field, a value nobody initialized, a race on a shared string. Large vendors keep reporting that memory-safety issues make up the majority of their high-severity vulnerabilities. The tools that prevent most of them already exist. Most teams just don't use them every day.

Memory-Safe C++ in Production shows you how to use them every day.

You won't get a lecture on best practices. You'll take one realistic service and harden it from start to finish. relay is a network-facing message gateway with an untrusted input boundary, shared state across threads, hot paths where every check has a cost, and third-party code nobody owns. It ships with eight seeded memory bugs, one or more for each bug class, plus two that aren't listed. Over thirteen chapters you'll find them, fix them so their whole class can't come back, and build the tooling that catches the next one before it reaches production.

Every chapter ends with the Safety Ledger, a running record of what relay now enforces, what detects each bug class, which defects are still open, and what each step cost in measured performance. You always know what changed, what it bought and what it cost.

What you'll learn

  • Make spatial errors impossible to write. Use span-based interfaces, hardened libc++ and libstdc++ modes, C++26 contracts, Clang's Safe Buffers and checked parsing at the network boundary. Then measure the real cost of bounds checks, which is usually within noise, and fix the few that aren't.
  • Control lifetimes. Deal with dangling views, iterator invalidation, escaping lambdas, coroutine lifetime traps, shared_ptr cycles and use-after-move. Back up the fixes with explicit ownership, generational handles, arenas and compiler lifetime annotations.
  • Close the quiet bug classes. Cover type confusion, strict aliasing, unions versus std::variant, C++26 erroneous behavior, automatic variable initialization and checked integer arithmetic.
  • Build a sanitizer-first workflow. Run ASan, UBSan, MSan, TSan and HWASan on every build. Put GWP-ASan in production. Add static analysis with custom clang-tidy checks, and coverage-guided, stateful and differential fuzzing that runs continuously.
  • Harden what survives. Add stack protectors, _FORTIFY_SOURCE, control-flow integrity, shadow stacks, hardened allocators and ARM Memory Tagging, and verify all of it on the binary you actually ship.
  • Migrate real codebases. Audit by exposure. Define a safe subset the build enforces. Apply refactoring patterns that remove whole bug classes. Build safe C++/Rust interop with cxx. Decide rewrite versus harden honestly, one component at a time.
  • Run it as a program. Track metrics that can't be gamed, set up CI/CD safety gates and canary comparison, follow an incident runbook for memory corruption, and write a multi-year roadmap for a real organization.

What makes this book different

  • Every claim can be checked. Costs are measured with a stated protocol and reported as ranges, never as one convenient number from one machine.
  • Every technique is applied to real code that builds, runs and is tested under sanitizers. There is no pseudocode.
  • It's honest about limits. Hardened C++ is not memory-safe by construction, and the book says exactly where the remaining risk lives and how to contain it.
  • It covers the whole lifecycle, from the first build flag to production detection, incident response and the decision to rewrite.

Who it's for

The book is for engineers who ship and maintain production C++: application and systems developers, tech leads, security engineers and platform teams. You should know modern C++. You don't need prior experience with sanitizers, fuzzers or the memory model. Each tool is introduced from first principles before you rely on it.

Four reference appendices come with the book: a sanitizer and hardening flag reference, an undefined behavior catalog, a static analysis check reference and a memory safety audit checklist you can run on your own codebase tomorrow.

Lock-Free C++ in Production

Lock-Free C++ in Production

Mastering the Memory Model with Hazard Pointers and Epoch-Based Reclamation

our lock-free queue passed every test. It ran clean under ThreadSanitizer for a year. Then it moved to ARM servers and started returning corrupted data, with no crash and no warning.

This book is about that gap between code that runs and code that is correct.

Most lock-free code works because of hardware it was never written for. x86 quietly adds orderings the code never asked for, and test machines rarely stall a thread at the worst possible instruction. This book shows you how to build lock-free C++ that is correct by proof rather than by luck, and how to verify it on every architecture you ship to.

What you’ll learn:

  • The C++ memory model, precisely. Every ordering is justified by the happens-before edge it creates, not by what one CPU happens to do.
  • Production data structures. SPSC, MPSC and MPMC queues, the Michael-Scott queue, Chase-Lev work-stealing, lock-free hash maps, skip lists, seqlocks, RCU and MCS locks, each with its progress guarantee stated.
  • Memory reclamation, solved. Hazard pointers, epoch-based reclamation, QSBR and interval-based schemes, built from the algorithm up to production domains, including C++26’s std::hazard_pointer and std::rcu.
  • Verification that finds real bugs. ThreadSanitizer’s blind spots, controlled scheduling, model checking with GenMC and Relacy, and linearizability checking.
  • Performance that holds up. False sharing, contention management, scalability measurement and NUMA placement.
  • Running it in production. Misuse-resistant APIs, debugging with core dumps and rr, and porting from x86 to ARM.

Every structure ships with complete, compilable modern C++, its stress test, and the deliberate bugs that prove the tests can catch it.

For C++ engineers who will run lock-free code in production, and who need it to be right.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub