High Performance Python, 3rd Edition

Book description

Your Python code may run correctly, but what if you need it to run faster? This practical book shows you how to locate performance bottlenecks and significantly speed up your code in high-data-volume programs. By explaining the fundamental theory behind design choices, this expanded edition of High Performance Python helps experienced Python programmers gain a deeper understanding of Python's implementation.

How do you take advantage of multicore architectures or clusters? Or build a system that scales up and down without losing reliability? Authors Micha Gorelick and Ian Ozsvald reveal concrete solutions to many issues and include war stories from companies that use high-performance Python for social media analytics, productionized machine learning, and more.

  • Get a better grasp of NumPy, Cython, and profilers
  • Learn how Python abstracts the underlying computer architecture
  • Use profiling to find bottlenecks in CPU time and memory usage
  • Write efficient programs by choosing appropriate data structures
  • Speed up matrix and vector computations
  • Process DataFrames quickly with pandas, Dask, and Polars
  • Speed up your neural networks and GPU computations
  • Use tools to compile Python down to machine code
  • Manage multiple I/O and computational operations concurrently
  • Convert multiprocessing code to run on local or remote clusters
  • Deploy code faster using tools like Docker

Publisher resources

View/Submit Errata

Table of contents

  1. Brief Table of Contents (Not Yet Final)
  2. 1. Understanding Performant Python
    1. The Fundamental Computer System
      1. Computing Units
      2. Memory Units
      3. Communications Layers
    2. Putting the Fundamental Elements Together
      1. Idealized Computing Versus the Python Virtual Machine
    3. So Why Use Python?
    4. How to Be a Highly Performant Programmer
      1. Good Working Practices
      2. Optimizing for the Team Rather than the Code Block
      3. The Remote Performant Programmer
      4. Some Thoughts on Good Notebook Practice
      5. Getting the Joy Back into Your Work
    5. The future of Python
      1. Where did the GIL go?
      2. Does Python have a JIT?
  3. 2. Profiling to Find Bottlenecks
    1. Profiling Efficiently
    2. Introducing the Julia Set
    3. Calculating the Full Julia Set
    4. Simple Approaches to Timing—print and a Decorator
    5. Simple Timing Using the Unix time Command
    6. Using the cProfile Module
    7. Visualizing cProfile Output with SnakeViz
    8. Using line_profiler for Line-by-Line Measurements
    9. Using memory_profiler to Diagnose Memory Usage
    10. Combining CPU and Memory Profiling with Scalene
    11. Introspecting an Existing Process with PySpy
    12. VizTracer for an interactive time-based call stack
    13. Bytecode: Under the Hood
      1. Using the dis Module to Examine CPython Bytecode
      2. Digging into bytecode specialisation with Specialist
      3. Different Approaches, Different Complexity
    14. Unit Testing During Optimization to Maintain Correctness
      1. No-op @profile Decorator
    15. Strategies to Profile Your Code Successfully
    16. Wrap-Up
  4. 3. Lists and Tuples
    1. A More Efficient Search
    2. Lists Versus Tuples
      1. Lists as Dynamic Arrays
      2. Tuples as Static Arrays
    3. Wrap-Up
  5. 4. Dictionaries and Sets
    1. How Do Dictionaries and Sets Work?
      1. Inserting and Retrieving
      2. Deletion
      3. Resizing
      4. Hash Functions and Entropy
    2. Wrap-Up
  6. 5. Iterators and Generators
    1. Iterators for Infinite Series
    2. Lazy Generator Evaluation
    3. Wrap-Up
  7. About the Authors

Product information

  • Title: High Performance Python, 3rd Edition
  • Author(s): Micha Gorelick, Ian Oszvald
  • Release date: May 2025
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098165963