High Performance Python cover

High Performance Python

No rating yet
Word count
415K words
ISBN
9787115454898

Tags

Summary

High Performance Python is the simplified Chinese edition of the bestselling O'Reilly book of the same name, introduced and published by Posts & Telecom Press. The book has 12 chapters. Its subject is not Python syntax itself but a core question: when a program is not fast enough, how can you find the real bottleneck and make it faster with the right methods? The book begins with background knowledge on the computer's internal structure to help readers understand what costs Python's interpreted execution, object model, and memory allocation actually incur at a low level, so they understand "why it is slow." It then discusses the time and space overhead of basic data structures such as lists and tuples, dictionaries and sets; the lazy evaluation approach of iterators and generators; and NumPy-based matrix and vector computation—achieving order-of-magnitude speedups by pushing loops down to the C layer. At the tool level, the book explains how to use profilers to locate hotspots in CPU and memory consumption, how to benchmark and visualize, and how to avoid optimizing by feel; it also explains paths such as Cython and PyPy that compile Python code to machine code or use just-in-time compilation. In the concurrency and parallelism section, the book distinguishes the scenarios suited to multithreading, multiprocessing, and asynchronous I/O, explains the impact of the GIL on CPU-bound tasks, and shows how to turn multiprocessing code into a task system that can run on local or remote clusters and work queues. The final chapter uses several real cases to show the complete process of locating and solving performance problems in practical applications such as social media analysis and machine learning. The book is aimed at beginner-to-intermediate developers who already know Python and want to write efficient code.

Editor's review

很多 Python 教程教你「怎么把功能写出来」,这本书教你「怎么把写出来的东西跑快」。它的可贵之处在于不提供一堆零散的提速小技巧,而是先讲清计算机与 Python 对象模型的底层代价,再教你先测量、后优化的工作方法:先用剖析器找到真正的热点,再决定是换数据结构、改用 NumPy 向量化、上 Cython,还是换语言层面的运行时。 内容覆盖面相当完整:数据结构与内存、迭代器与生成器、矩阵运算、编译加速、并发与集群、任务队列,基本把 Python 性能这条线从单机优化到分布式扩展都串了起来。每章都配有可动手的实验代码,读完之后你不会只记住结论,而是能自己复现一遍测量和优化过程。 本书的作者一位来自数据工程一线,一位长期在 PyCon、PyData 授课,因此行文里带着大量工程直觉和踩坑经验。需要提醒的是,它假定你已熟悉 Python 基础语法,不是零基础入门书;书中的案例与工具体系以英文版写作时的生态为背景,部分具体版本细节需要结合官方文档更新。如果你正准备处理一个真的慢下来的项目,这本书会是很扎实的案头参考。

Who it's for

A good fit for

  • 已掌握 Python 基础语法、希望写出高效代码的初中级开发者
  • 做数据分析与科学计算、需要加速数值计算的工程师
  • 被线上服务响应速度或批处理耗时困扰的后端工程师
  • 想系统了解性能剖析、并发与并行模型的技术负责人

Not a good fit for

  • 完全没有 Python 编程经验的零基础读者
  • 只想查阅零散语法技巧、不打算动手测量的读者
  • 专注于前端或界面开发、无 Python 性能需求的人

Reading tips

  1. 先通读第 1—2 章理解底层代价,再按自己项目类型挑章节精读。
  2. 配合书中示例,在自己机器的同一份数据上跑一遍剖析与前后对比。
  3. 把「先测量、后优化」当作纪律,不要凭直觉改写代码。
  4. 并发与集群部分建议结合一个真实的小任务系统动手实践。

About the publisher

Posts & Telecom Press China · Founded in 1953

Posts & Telecom Press is known for its strengths in science and technology, computing, and information and communications titles, and has extended its publishing into photography, art, software learning, and inspirational growth, giving it a fairly diverse range. Its catalog includes computing and communications works such as Refactoring and Patterns (Revised Edition) and Huawei Switch Learning Guide (Second Edition), alongside bilingual collector's editions such as The Little Prince (Chinese-English-French illustrated collector's edition), The Great Gatsby, and Three Days to See. Beijing Ten Years: 1980-1990 and Ghost Blade: WLOP Personal Illustration Collection reflect its presence in photography and art. Its authors include Antoine de Saint-Exupéry, Helen Keller, Joshua Kerievsky, Wang Da, Zhang Zhaozeng, and WLOP.

FAQ

这本书适合零基础学 Python 吗?
不适合作为入门教材。本书默认读者已掌握 Python 基础语法,重点在于剖析与优化,若尚未写过完整脚本,建议先补一门 Python 基础课再读。
这本书和《Python高性能编程(第2版)》有什么区别?
第 2 版由张海龙翻译,2023 年由人民邮电出版社出版,ISBN 为 9787115599476,内容扩充到 12 章并新增异步 I/O、Docker 部署等话题。本条目对应的是 2017 年胡世杰、徐旭彬译本。
读这本书需要哪些前置知识?
需要会写 Python 函数与类、理解基本数据结构,并对操作系统进程、线程、内存有初步概念,其余如 NumPy、Cython 可在阅读中随书学习。
书里的代码和示例能直接用于生产吗?
示例主要用于演示测量与优化思路,可直接运行验证,但版本与工具生态在变化,落地时应结合当前官方文档核对 API 与最佳实践。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

Top rated in the same category