Python Core Architecture Roadmap
From Language Semantics to CPython Runtime, Source Reading, and Engineering Judgment
Part 1: Python Language Semantics
Chapter 1: Execution Model
- 1.1 code block 与 execution context(code block 决定编译单元,execution context 决定 globals、locals、builtins、frame 和异常状态)
- 1.2 module / function / class 的执行过程(module 顶层立即执行,function body 调用时执行,class body 执行后生成 class object 和 namespace)
- 1.3
eval/exec的动态执行模型(eval返回表达式结果,exec执行代码块并写入给定 globals/locals,二者都会重开编译与名字解析路径) - 1.4 frame 如何保存执行状态(frame 保存 code object、instruction pointer、value stack、fast locals、globals、builtins 和 traceback 连接点)
- 1.5 namespace 如何参与 name resolution(local、enclosing、global、builtins namespace 共同决定名字绑定、读取、覆盖和 NameError 触发位置)
- 1.6 builtins namespace 的最终查找层(builtins 是普通名字查找的最后一层,也是
len、open、Exception等内置对象进入代码块的入口) - 1.7 call stack 与 execution order(调用栈记录 frame 嵌套顺序,解释器按当前 frame 的指令流推进并在调用、返回、异常时切换 frame)
- 1.8 frame lifecycle 与 Runtime state(frame 会在调用创建、执行中更新、异常时挂入 traceback、生成器中暂停、返回后释放或被调试工具保留)
Chapter 2: Name Binding and Scope
- 2.1 Name binding and namespace ownership(说明 name binding 如何把名字放入 local、global、enclosing 或 builtins namespace)
- 2.2 LEGB lookup chain(追踪普通名字查找如何沿 local、enclosing、global、builtins 顺序定位对象)
- 2.3 Free variable, cell variable, and closure capture(整理 closure 如何通过 cell 保存外层变量并影响后续访问)
- 2.4 global, nonlocal, and comprehension scope(说明显式作用域声明和推导式作用域如何改变绑定位置)
- 2.5 Compile-time symbol table analysis(提取 symbol table 如何提前分类名字并决定 runtime 查找路径)
Chapter 3: Object Reference Semantics
- 3.1 object identity 与 equality(
is比较对象身份,==走类型的比较协议;二者会在缓存对象、interning 和自定义__eq__中分离) - 3.2 mutability 与 immutability(list/dict/set 修改同一对象内部状态,int/str/tuple 等值变化通常表现为新对象绑定)
- 3.3 aliasing 与 reference sharing(多个名字可以指向同一对象,共享引用会让局部修改变成跨调用方可见状态变化)
- 3.4 parameter passing 的真实行为(函数参数绑定的是对象引用,调用不会复制对象;可变对象修改和名字重新绑定产生不同后果)
- 3.5 shallow copy 与 deep copy(shallow copy 复制容器外层,deep copy 递归复制对象图,并需要处理循环引用、共享引用和自定义 copy 协议)
- 3.6 mutable default argument(默认参数在函数定义时创建并挂在 function object 上,多次调用共享同一个默认对象)
- 3.7 object lifetime 与 reference graph(对象生命周期由引用图、引用计数、循环 GC、临时对象和 traceback/frame 持有关系共同决定)
Chapter 4: Evaluation Semantics
- 4.1 Evaluation order and expression sequencing(说明表达式求值顺序如何决定对象创建、调用和副作用发生时机)
- 4.2 Truth testing and short-circuit evaluation(整理 truth value testing、and/or 的短路路径和返回值边界)
- 4.3 Attribute reference and call expression evaluation(追踪属性访问和函数调用如何先求值对象、参数和 callable)
- 4.4 Slicing, lambda, walrus, and operator precedence(说明特殊表达式如何参与临时对象、绑定和优先级判断)
- 4.5 Lazy evaluation and side effects(提炼延迟求值场景下副作用、对象状态和调试判断顺序)
Chapter 5: Control Flow Semantics
- 5.1
if/while/for(条件分支、循环条件和迭代协议会被编译成跳转、比较、iterator 获取和异常结束路径) - 5.2 iterator-driven loop(
for会先调用iter()获得 iterator,再反复调用next(),以StopIteration作为正常结束信号) - 5.3
break/continue(break跳出当前循环,continue回到下一轮条件或迭代点,并与finallycleanup 顺序交织) - 5.4 loop else 的语义(loop
else在循环自然结束时执行,被break中断时跳过,适合表达“搜索未提前命中”的控制流) - 5.5 pattern matching(match 会按 case 顺序执行结构匹配、类型/值检查、捕获绑定和解构,并在命中后进入对应 block)
- 5.6 guard condition(case guard 在结构匹配成功后求值,guard 失败会继续尝试后续 case,并保留匹配语义的短路顺序)
- 5.7 exception-driven flow(异常路径会切换控制流、保存 traceback、执行匹配 handler,并触发 finally/context manager cleanup)
- 5.8 context-driven flow(
with、async with把入口、退出、异常处理和资源释放包装成协议驱动的控制流)
Chapter 6: Exception Semantics
- 6.1 Exception object propagation and traceback chain(追踪异常对象如何携带 traceback 沿调用栈传播)
- 6.2 Exception chaining and hierarchy(整理 exception chaining、BaseException、Exception 和常见异常族的关系)
- 6.3 finally cleanup and stack unwinding(说明 finally、with cleanup 和 stack unwinding 如何收束资源状态)
- 6.4 Exception table and zero-cost exception path(提取 CPython 3.11+ exception table 如何改变正常路径和异常路径成本)
- 6.5 ExceptionGroup and runtime error state(说明 exception group、except* 和 runtime error state 的边界)
Chapter 7: Context Management Semantics
- 7.1 context manager protocol(context manager 用
__enter__、__exit__定义资源进入、绑定、异常接收和退出处理) - 7.2
withstatement(with会先求值 manager,调用__enter__,执行 body,再把异常信息交给__exit__) - 7.3
__enter__/__exit__(__enter__返回绑定值,__exit__接收 exc_type、exc、traceback,并用返回值决定异常是否继续传播) - 7.4 deterministic cleanup(文件、锁、事务、临时目录和网络连接可以通过 context manager 获得确定的退出顺序)
- 7.5 exception suppression(当
__exit__返回真值时异常被吞掉,这会改变调用方看到的控制流和错误状态) - 7.6
async with(async with使用__aenter__、__aexit__,清理动作本身可以 await,适合异步连接、锁和 session) - 7.7 ExitStack / AsyncExitStack(ExitStack 动态注册多个退出回调,并按后进先出顺序释放资源,适合资源数量运行时才确定的场景)
- 7.8 resource lifecycle management(资源生命周期分析需要确认获取点、所有权、退出顺序、异常路径和重复释放保护)
Part 2: Python Object System
Chapter 8: Everything Is Object
- 8.1 PyObject identity and type pointer(说明 PyObject、object identity、object type 如何构成 Python 对象最小模型)
- 8.2 Object header, ob_refcnt, and ob_type(整理对象头部字段如何支撑引用计数和动态分发)
- 8.3 Object memory layout and allocation kind(区分 object memory layout、heap object、static object 和 immortal object)
- 8.4 Object allocation, destruction, and lifecycle(追踪对象创建、引用变化、销毁和复用的 runtime 路径)
- 8.5 Everything is object as a runtime rule(把一切皆对象整理成可用于解释函数、类、模块和值的判断模型)
Chapter 9: Type System
- 9.1 PyTypeObject, type, and object hierarchy(整理 PyTypeObject、type、object 和类型层级的启动关系)
- 9.2 Slot mechanism and dynamic dispatch(说明 slot 如何把 Python 操作映射到类型级分发表)
- 9.3 Duck typing and special method lookup(追踪协议调用、duck typing 和 special method lookup 的边界)
- 9.4 Type cache and runtime polymorphism(说明 type cache 如何降低动态派发成本并保持语义)
- 9.5 Heap type, static type, and runtime mutation(区分 heap type、static type 和运行时类型变更的能力边界)
Chapter 10: Attribute Lookup System
- 10.1 Attribute lookup chain(追踪 attribute lookup 如何从实例、类、MRO 和 descriptor 中定位结果)
- 10.2 Instance dict, class dict, and shadowing(整理 instance dict、class dict 和 attribute shadowing 的覆盖关系)
- 10.3 getattribute, getattr, setattr, and delattr(说明四个钩子如何接管读取、兜底、写入和删除路径)
- 10.4 Descriptor lookup and precedence(区分 data descriptor、non-data descriptor、普通属性和缓存路径)
- 10.5 Method lookup and LOAD_ATTR specialization(提取 method binding、attribute cache 和 LOAD_ATTR specialization 的 runtime 结论)
Chapter 11: Descriptor Protocol
- 11.1 Descriptor protocol contract(说明 get、set、delete 如何定义 descriptor 协议)
- 11.2 Data descriptor and non-data descriptor precedence(整理两类 descriptor 和实例属性之间的优先级)
- 11.3 Function descriptor and method binding(追踪 function descriptor 如何生成 bound method)
- 11.4 property, classmethod, and staticmethod(说明常见内置 descriptor 如何改变 attribute access 语义)
- 11.5 Descriptor cache and engineering boundaries(提炼 descriptor cache、可读性、调试和设计边界)
Chapter 12: Function Object Internals
- 12.1 Function object and code object(说明 function object 如何持有 code object、globals、defaults 和 metadata)
- 12.2 Defaults, kwdefaults, annotations, and metadata(整理函数静态信息如何影响调用、检查和工具行为)
- 12.3 Closure and cell object(追踪 closure 如何通过 cell object 保存外部绑定)
- 12.4 Callable protocol, vectorcall, and bound method(说明 callable dispatch、vectorcall、bound method 和 wrapper function 的调用路径)
- 12.5 Function and frame relationship(提取函数调用如何创建 frame 并进入执行状态)
Chapter 13: Class Construction
- 13.1 Class body execution and namespace creation(说明 class body 如何作为代码块执行并生成 class namespace)
- 13.2 Metaclass selection and prepare(追踪 metaclass selection 如何决定 namespace 准备对象)
- 13.3 type.new, type.init, and class object creation(整理 type.new、type.init 如何创建并初始化类对象)
- 13.4 init_subclass, slots, and class cell(说明类创建后钩子、slots 和 class cell 的边界)
- 13.5 Dynamic class creation path(提炼动态建类时 namespace、metaclass、descriptor 和 MRO 的检查顺序)
Chapter 14: Inheritance and MRO
- 14.1 Inheritance model and MRO(整理继承结构如何生成 method resolution order)
- 14.2 C3 linearization and diamond inheritance(说明 C3 如何处理菱形继承和局部顺序约束)
- 14.3 super and cooperative inheritance(追踪 super 如何沿 MRO 协作调用)
- 14.4 Mixin design and descriptor interaction(说明 mixin、descriptor 和 method lookup 的组合边界)
- 14.5 Metaclass interaction(提炼继承体系中 metaclass 选择和冲突的判断方法)
Chapter 15: Metaclass System
- 15.1 Metaclass and type bootstrapping(说明 type 作为 metaclass 如何支撑类对象创建)
- 15.2 Custom metaclass and metaclass conflict(整理自定义 metaclass 的能力和冲突条件)
- 15.3 Dynamic class creation and runtime type mutation(追踪动态建类和运行时类型修改的对象路径)
- 15.4 PyType_Type and metaclass dispatch(提取 CPython 类型对象层级中的关键实现关系)
- 15.5 Metaclass engineering boundaries(提炼 metaclass 适用场景、可维护性和替代方案判断)
Part 3: Builtins and Core Protocols
Chapter 16: Built-in Functions
- 16.1 Iteration and size builtins(整理 len、iter、next 如何通过协议访问对象能力)
- 16.2 Type and identity builtins(说明 type、isinstance、issubclass、id 如何查询对象和类型关系)
- 16.3 Attribute and callable builtins(追踪 getattr、setattr、hasattr、callable 如何进入 attribute 或 call protocol)
- 16.4 Representation and formatting builtins(整理 repr、str、format 如何生成用户可见表示)
- 16.5 Resource and evaluation builtins(说明 open、eval、exec 等 builtins 如何跨入 I/O 或动态执行边界)
- 16.6 Builtins as protocol surface(提炼 builtins 如何把语法和对象协议连接成统一接口)
Chapter 17: Built-in Exceptions
- 17.1 Exception hierarchy roots(整理 BaseException、Exception 和非普通控制流异常的层级)
- 17.2 Common runtime exception families(说明 TypeError、ValueError、AttributeError、LookupError 的触发边界)
- 17.3 Iteration and generator control exceptions(追踪 StopIteration、GeneratorExit 和 generator/coroutine 控制路径)
- 17.4 Traceback and exception chaining(整理 traceback relation、cause、context 和 propagation)
- 17.5 Built-in exceptions as runtime contracts(提炼异常类型如何表达协议失败、状态错误和恢复方向)
Chapter 18: Core Protocols
- 18.1 Iteration, sequence, and mapping protocols(整理容器协议如何支撑 for、索引、切片和键查找)
- 18.2 Numeric and comparison protocols(说明运算符如何通过类型 slot 和 special method 分发)
- 18.3 Callable, descriptor, and context manager protocols(追踪调用、属性绑定和资源上下文协议)
- 18.4 Async and buffer protocols(说明异步执行和二进制内存视图的协议入口)
- 18.5 Protocol dispatch model(提炼 Python 行为如何从语法落到对象协议和 runtime 分发)
Chapter 19: Iteration, Sequence, and Mapping Protocols
- 19.1 Iterator Protocol and for Loop Dispatch(追踪 iter、next、StopIteration 和 for loop 之间的执行路径)
- 19.2 Sequence Protocol and Indexing Semantics(说明索引、切片、长度和 containment 如何进入对象协议)
- 19.3 Mapping Protocol and Key Lookup(整理 dict-like 对象的键查找、缺失处理和更新边界)
- 19.4 Protocol Fallback and Special Method Lookup(区分协议查找、slot dispatch、普通 attribute lookup 和 fallback 路径)
- 19.5 Protocol Reading Checklist(给出从语法现象回到 special method、slot 和 runtime 分发的检查顺序)
Chapter 20: Numeric, Comparison, and Hashing Protocols
- 20.1 Numeric Slot Dispatch(追踪算术运算如何进入类型 slot、反向运算和 inplace 运算)
- 20.2 Rich Comparison and Ordering Semantics(说明 equality、ordering、NotImplemented 和多类型比较的返回路径)
- 20.3 Hash Contract and Dictionary Membership(整理 hash、equality 和 dict/set key 稳定性之间的关系)
- 20.4 Operator Overloading Boundaries(区分可重载语法、不可重载语法和协议设计成本)
- 20.5 Debugging Broken Numeric Behavior(给出从运算符现象回到 slot、返回值和对象状态的排查顺序)
Chapter 21: Callable, Context, Async, and Buffer Protocols
- 21.1 Callable Protocol and Vectorcall Surface(说明 callable object 如何通过 call、vectorcall 和 bound method 进入调用路径)
- 21.2 Context Manager Protocol as Resource Boundary(追踪 enter、exit、异常传递和资源收束之间的关系)
- 21.3 Awaitable and Async Iterator Protocols(整理 await、async for、async with 背后的协议入口和状态变化)
- 21.4 Buffer Protocol and Binary Data Sharing(说明 bytes-like 对象、memoryview 和 native buffer 之间的共享边界)
- 21.5 Protocol Composition Checklist(给出多个协议叠加时定位对象能力、执行入口和失败原因的顺序)
Part 4: Compilation Pipeline
Chapter 22: Tokenizer and PEG Parser
- 22.1 Lexical analysis and tokenizer(说明源文本如何被 tokenizer 转成 token stream)
- 22.2 PEG parser, grammar, and parse tree(追踪 token stream 如何按照 PEG grammar 形成结构)
- 22.3 Parser state and parser evolution(整理 parser state、错误恢复和 CPython parser 演进边界)
- 22.4 Syntax error recovery(说明语法错误如何定位 token、源码范围和上下文)
- 22.5 Token stream as compiler input(提炼 token、grammar 和后续 AST 之间的责任边界)
Chapter 23: AST and Symbol Table
- 23.1 AST as structured syntax(说明 AST 和 syntax tree 如何表达源码结构)
- 23.2 Symbol table and scope analysis(追踪 symbol table 如何分析 local、global、free 和 cell 变量)
- 23.3 Free variable analysis and compiler metadata(整理闭包变量、metadata 和 compiler state 的关系)
- 23.4 AST transformation and validation(说明 AST transformation 可以改变什么,以及需要保持哪些结构约束)
- 23.5 AST to compiler state boundary(提炼 AST、symbol table 和后续 CFG/bytecode 的交接点)
Chapter 24: CFG and Bytecode Generation
- 24.1 Control flow graph construction(说明 CFG 如何表达分支、循环、异常和跳转目标)
- 24.2 Bytecode generation and opcode selection(追踪 AST/CFG 如何生成 opcode、constants table 和 names table)
- 24.3 Compiler passes and optimization pass(整理 compiler passes 如何改变 CFG 或 bytecode 形态)
- 24.4 Jump target, stacksize, and exception table(说明跳转、栈深和 exception table 如何影响执行器)
- 24.5 CFG to bytecode boundary(提炼从结构控制流到 stack machine 指令的转换判断)
Chapter 25: Bytecode Architecture
- 25.1 Bytecode format, opcode system, and stack machine(说明 CPython bytecode 如何作为 stack machine 指令流执行)
- 25.2 dis module as observation tool(整理 dis 输出如何对应 opcode、argument 和 source position)
- 25.3 Inline cache and adaptive opcode(追踪 inline cache、adaptive opcode 和 opcode specialization 的 runtime 路径)
- 25.4 Bytecode evolution and instruction family(说明版本演进如何改变指令形态和阅读边界)
- 25.5 Bytecode reading checklist(提炼从源码现象回到指令、栈效果和缓存状态的检查顺序)
Chapter 26: Adaptive Runtime (PEP 659)
- 26.1 Quickening and adaptive bytecode(说明 quickening 如何把普通 bytecode 转成可 specialization 的形态)
- 26.2 Specialization family and inline cache system(整理 specialization family、inline cache 和 adaptive counter 的关系)
- 26.3 De-optimization and runtime patching(追踪假设失效时如何回退或替换指令)
- 26.4 Performance boundary of adaptive runtime(说明 adaptive interpreter 能优化的路径和无法改变的成本)
- 26.5 PEP 659 reading model(提炼从 opcode、cache、counter 和对象类型读性能行为的方法)
Part 5: Evaluation Runtime
Chapter 27: Execution Engine
- 27.1
ceval.c(把ceval.c作为 bytecode 执行入口,定位 eval loop、opcode handler、frame 状态和 eval breaker) - 27.2 evaluation loop(evaluation loop 反复读取 opcode、操作 value stack、更新 instruction pointer,并在调用、异常、yield 时切换路径)
- 27.3 opcode dispatch(opcode dispatch 决定当前指令进入哪个 handler,影响解释器分支成本、specialization 和调试阅读方式)
- 27.4 stack VM 的运行方式(CPython bytecode 使用 value stack 传递中间值,表达式、调用、属性访问和异常都通过栈效果连接)
- 27.5 instruction pointer 如何推进(instruction pointer 在普通指令、跳转、异常表、yield/resume 和 quickened instruction 中按不同规则推进)
- 27.6 computed goto(computed goto 把 opcode dispatch 从集中 switch 变成直接跳转表,减少解释器分派开销)
- 27.7 runtime dispatch(运行时分派会根据 opcode、object type、slot、descriptor、vectorcall 和 inline cache 选择具体执行路径)
- 27.8 eval breaker(eval breaker 汇合 signal、pending call、GIL drop、async exception 等跨指令检查点)
Chapter 28: Execution State and Frame
- 28.1 PyFrameObject and frame stack(说明 frame 对象如何保存执行上下文并进入调用栈)
- 28.2 Value stack, block stack, and fast locals(整理 frame 内部状态如何支撑表达式、异常和局部变量)
- 28.3 Traceback and frame introspection(追踪 traceback 和 inspect 如何观察执行状态)
- 28.4 Frame suspension and generator frame(说明 generator/coroutine 如何让 frame 暂停并恢复)
- 28.5 Frame lifecycle(提炼 frame 创建、执行、挂起、销毁和复用的判断顺序)
Chapter 29: Callable Runtime
- 29.1 vectorcall and call protocol(说明 vectorcall 如何优化 Python callable 调用路径)
- 29.2 Argument binding(整理 positional argument、keyword argument、defaults 和 varargs 如何进入参数绑定)
- 29.3 Call stack and recursion(追踪调用嵌套、递归限制和 frame allocation)
- 29.4 Fast locals and execution entry(说明参数如何进入 fast locals 并开始执行 code object)
- 29.5 Callable runtime checklist(提炼从 call expression 到 frame 状态的检查顺序)
Chapter 30: Suspended Execution Model
- 30.1 Generator object and suspended frame(说明 generator 如何把函数执行状态保存成 suspended frame)
- 30.2 yield, send, throw, and close(追踪 generator 的四类交互如何改变状态和异常路径)
- 30.3 yield from delegation(整理 yield from 如何转发值、异常和返回值)
- 30.4 Frame persistence and lazy execution(说明惰性执行如何延长 frame 和局部对象生命周期)
- 30.5 Suspended execution boundaries(提炼生成器、协程和普通调用之间的判断维度)
Chapter 31: Async Runtime
- 31.1 Coroutine object and awaitable protocol(说明 async function 调用后如何产生 coroutine object)
- 31.2 await and coroutine suspension(追踪 await 如何挂起当前协程并等待 awaitable)
- 31.3 Task scheduling and Future relation(整理 task、future 和 event loop 的责任关系)
- 31.4 Async state machine and cancellation(说明协程状态转换、取消和异常传播边界)
- 31.5 Async runtime checklist(提炼从 async 代码现象回到 coroutine、task 和 event loop 的判断顺序)
Part 6: Memory System
Chapter 32: Reference Counting
- 32.1 ob_refcnt, incref, and decref(说明引用计数如何记录对象可达引用数量)
- 32.2 Ownership model: borrowed, strong, and temporary references(整理不同引用所有权在 C API 和 Python runtime 中的边界)
- 32.3 Reference leak and reference graph(追踪泄漏如何从引用关系和生命周期不匹配中产生)
- 32.4 Cyclic reference boundary(说明引用计数为何需要配合 cyclic GC 处理环)
- 32.5 Reference counting checklist(提炼创建、传递、保存、释放引用时的检查顺序)
Chapter 33: Garbage Collection
- 33.1 Cyclic GC and generational GC(说明循环垃圾回收和分代策略各自解决的问题)
- 33.2 Object tracking, GC root, and unreachable objects(追踪对象如何被跟踪、标记为不可达并进入 collection cycle)
- 33.3 Finalizer, weakref, and resurrection(整理 finalizer、weakref 和对象复活带来的边界)
- 33.4 Collection cycle and runtime cost(说明 GC 周期如何影响暂停、内存和对象生命周期)
- 33.5 GC diagnosis checklist(提炼从引用图、tracking 状态和 finalizer 风险分析内存问题的方法)
Chapter 34: Pymalloc Architecture
- 34.1 arena / pool / block(pymalloc 把内存分成 arena、pool、block,用 size class 管理小对象分配与回收)
- 34.2 small object allocator(小对象走 pymalloc 快速路径,大对象交给系统 allocator,二者会影响内存峰值和 profile 解读)
- 34.3 freelist(tuple、list、frame 等对象可能使用 freelist 复用对象壳,释放后内存表现可能滞后于对象生命周期)
- 34.4 allocator hierarchy(PyMem、PyObject、raw allocator、domain hook 形成多层 allocator 接口,扩展模块需要选对域)
- 34.5 memory fragmentation(fragmentation 来自 size class、arena 保留、长寿命对象夹杂短寿命对象和 workload shape)
- 34.6 allocation class(size class 决定对象进入哪个 pool,微小尺寸变化可能改变分配路径和内存占用)
- 34.7 object reuse(对象复用会影响
id()观察、内存调试、泄漏判断和 benchmark 稳定性)
Chapter 35: Immortal Objects (PEP 683)
- 35.1 immortal object(immortal object 用特殊 refcount 表示长期存活对象,减少共享对象上的引用计数写入)
- 35.2 cache line optimization(频繁修改 refcount 会造成 cache line 写压力,immortal object 能降低热门常量对象的写流量)
- 35.3 GC bypass(部分 immortal/static 对象无需进入普通回收路径,阅读内存行为时要区分普通 heap object)
- 35.4 runtime optimization(immortal object 服务解释器启动对象、内置单例、常用常量和多解释器共享对象的运行时成本控制)
- 35.5 copy-on-write(fork 后共享内存页遇到 refcount 写入会触发 copy-on-write,immortal refcount 可减少这类写入)
- 35.6 object sharing(多解释器和未来并行运行时需要更清楚地定义哪些对象可共享、哪些对象必须隔离)
- 35.7 no-GIL preparation(no-GIL 方向需要降低全局共享对象上的原子写压力,immortal object 是其中一个支撑机制)
- 35.8 immortal refcount(immortal refcount 是一个约定值,普通 INCREF/DECREF 路径会识别并保留该状态)
Part 7: Core Containers
Chapter 36: Dict Architecture
- 36.1 Compact hash table and insertion order(说明 dict 如何把哈希表和插入顺序结合起来)
- 36.2 Probing, resizing, and hash randomization(整理查找路径、扩容和随机化如何影响性能和安全)
- 36.3 Split table, combined table, and key-sharing dict(说明实例属性存储和普通 dict 存储的结构差异)
- 36.4 Globals lookup and attribute storage(追踪 dict 如何服务 namespace、globals lookup 和 object attribute)
- 36.5 Dict architecture checklist(提炼从 key、hash、probe、resize 和 storage mode 判断 dict 行为的方法)
Chapter 37: List and Tuple Architecture
- 37.1 List dynamic array and over-allocation(说明 list 如何用动态数组和 over-allocation 支撑 append)
- 37.2 Tuple immutability and freelist(整理 tuple 的不可变语义、对象复用和内存边界)
- 37.3 Slicing, append growth, and memory locality(追踪 list/tuple 操作如何影响复制、增长和 cache locality)
- 37.4 Iteration cost and sequence optimization(说明顺序访问成本和优化路径)
- 37.5 List and tuple selection checklist(提炼可变性、大小变化、共享风险和访问模式的判断方法)
Chapter 38: Set Architecture
- 38.1 Hash set layout and probing strategy(说明 set 如何用哈希表结构表达唯一元素集合)
- 38.2 Collision handling and resizing(整理冲突、探测和扩容如何影响 membership optimization)
- 38.3 Set operations and hash invariant(追踪并集、交集、差集如何依赖 hash/equality 不变量)
- 38.4 Set iteration and ordering boundary(说明 set 迭代顺序的稳定性边界)
- 38.5 Set architecture checklist(提炼从元素可哈希性、成员查询和批量集合操作选择 set 的方法)
Chapter 39: Buffer and Binary Architecture
- 39.1 Buffer protocol and memoryview(说明 buffer protocol 如何把二进制内存暴露为可共享视图)
- 39.2 Zero-copy, contiguous memory, and binary view(整理零拷贝成立条件、连续性和视图边界)
- 39.3 Bytes-like object and binary slicing(追踪 bytes、bytearray、memoryview 的切片和复制行为)
- 39.4 C interop and binary performance(说明 C 扩展、I/O 和数值计算如何使用 buffer)
- 39.5 Binary architecture checklist(提炼从所有权、连续性、可变性和复制成本判断二进制数据路径)
Part 8: Import System
Chapter 40: Import Semantics
- 40.1 Module and package objects(说明 module object 与 package object 如何成为 import 结果对象)
- 40.2 Module execution and sys.modules cache(追踪模块执行、import cache 和 sys.modules 的状态变化)
- 40.3 Import lock and relative import(整理并发 import 和相对导入的边界)
- 40.4 Import cycle and module state(说明循环导入如何产生半初始化模块)
- 40.5 Import semantics checklist(提炼从 import 语句到模块对象状态的检查顺序)
Chapter 41: Import Machinery
- 41.1 Finder, loader, and ModuleSpec(说明 import machinery 如何通过 ModuleSpec 描述加载计划)
- 41.2 Meta path and path hook(整理 meta path、path hook 和搜索路径的责任分工)
- 41.3 importlib and namespace package(追踪 importlib 如何实现加载流程和 namespace package)
- 41.4 Module initialization and lazy import(说明模块初始化、延迟导入和可观察行为的边界)
- 41.5 Import machinery checklist(提炼从模块名定位到 loader 执行的完整路径)
Chapter 42: Module Object, sys.modules, and Import Cache
- 42.1 Module Object as Runtime State Container(说明 module 对象如何保存 globals、metadata 和执行结果)
- 42.2 sys.modules as Import Cache(追踪 sys.modules 如何记录已加载模块并改变后续 import 行为)
- 42.3 Partial Initialization and Circular Import State(整理循环导入中半初始化 module 的可见状态和错误表现)
- 42.4 Reload, Cache Invalidation, and Identity Risk(说明 reload 和缓存失效如何影响 module identity、class identity 和运行中对象)
- 42.5 Import Cache Debugging Checklist(给出从导入异常、旧对象、循环依赖到 sys.modules 状态的排查顺序)
Chapter 43: Packages, Namespace Packages, and Resource Loading
- 43.1 Package as Module Plus Search Path(说明 package 如何通过 path、submodule 和 metadata 组织命名空间)
- 43.2 Namespace Package and Multi-Location Discovery(追踪 namespace package 如何聚合多个目录或分发来源)
- 43.3 Relative Import and Package Context(整理 relative import 如何依赖 package、module name 和执行入口)
- 43.4 importlib.resources and Package Data(说明资源文件如何通过 package 边界被访问和分发)
- 43.5 Package Boundary Checklist(给出从目录结构、模块名、搜索路径到资源访问的检查顺序)
Chapter 44: Import Failure, Finder Loader Contracts, and Diagnostics
- 44.1 ModuleSpec as Import Contract(说明 ModuleSpec 如何连接 finder、loader、origin 和 module 创建过程)
- 44.2 Finder and Loader Failure Points(追踪查找失败、加载失败、执行失败对应的不同异常和状态)
- 44.3 Import Side Effects and Execution Timing(整理 module 顶层代码执行、缓存写入和副作用发生顺序)
- 44.4 Custom Import Hooks and Plugin Loading(说明 meta_path、path hooks 和自定义 loader 如何扩展导入机制)
- 44.5 Import Diagnostic Checklist(给出从 ModuleNotFoundError、AttributeError、循环导入到路径配置的定位顺序)
Part 9: Concurrency Runtime
Chapter 45: GIL Internals
- 45.1 GIL, interpreter state, and thread state(说明 GIL 如何保护 interpreter state 和 thread state 的执行边界)
- 45.2 Bytecode lock, thread switching, and eval breaker(追踪解释器循环中线程切换和 eval breaker 的触发点)
- 45.3 CPU-bound limitation and I/O behavior(整理 GIL 对 CPU 密集和 I/O 密集任务的不同影响)
- 45.4 Atomic illusion and extension boundary(说明原子错觉、C 扩展释放 GIL 和数据竞争边界)
- 45.5 GIL diagnosis checklist(提炼从线程状态、锁持有、I/O 等待和扩展代码分析并发问题的方法)
Chapter 46: Async Runtime Architecture
- 46.1 Event loop, task, and future(说明 asyncio 运行时如何用 event loop 调度 task 和 future)
- 46.2 Cooperative scheduling(整理协作式调度如何依赖 await 让出控制权)
- 46.3 Cancellation and async state(追踪取消请求如何沿 await 链传播并进入清理逻辑)
- 46.4 Async queue, lock, and callback scheduling(说明异步同步原语和 callback 如何影响公平性与背压)
- 46.5 Async runtime architecture checklist(提炼从卡顿、泄漏、取消和顺序问题回到 event loop 的判断方法)
Chapter 47: Subinterpreters (PEP 684)
- 47.1 subinterpreter(subinterpreter 在同一进程内创建独立解释器状态,用于隔离模块状态、线程状态和运行时资源)
- 47.2 per-interpreter GIL(per-interpreter GIL 让不同解释器拥有各自锁,目标是让独立解释器中的 Python 代码并行执行)
- 47.3 interpreter isolation(隔离重点是 module state、thread state、object ownership、extension module state 和 cross-interpreter data)
- 47.4 parallel execution(并行收益取决于解释器隔离、可传输数据、扩展模块兼容性和任务粒度)
- 47.5 runtime separation(runtime separation 要明确全局 runtime state、per-interpreter state、per-thread state 分别保存什么)
- 47.6 interpreter state(PyInterpreterState 保存模块表、builtins、import state、GC state、thread list 和 runtime config 的解释器级状态)
- 47.7 object isolation(对象跨解释器共享需要满足安全传递规则,普通 Python 对象通常通过复制、序列化或专门 channel 传递)
Chapter 48: Free-Threaded Python
- 48.1 no-GIL architecture(free-threaded CPython 移除全局解释器锁后,需要重新设计 refcount、container lock、allocator 和 extension safety)
- 48.2 lock strategy(list、dict、object state、runtime global state 需要更细粒度锁或无锁策略来保护并发访问)
- 48.3 runtime tradeoff(free-threaded 模式提升 CPU 并行潜力,同时引入锁成本、原子操作成本、兼容性成本和调试复杂度)
- 48.4 memory synchronization(并发线程之间的对象状态可见性依赖 atomic、lock、critical section 和 memory ordering 约束)
- 48.5 atomic reference counting(引用计数更新需要支持并发安全,atomic refcount、biased/deferred 方案会改变对象生命周期成本)
- 48.6 runtime redesign(解释器、GC、allocator、C API、extension state 都要围绕并发访问重新定义约束)
- 48.7 CPython future roadmap(用 PEP 684、PEP 683、PEP 703 串起多解释器、immortal object、free-threaded 的演进关系)
Part 10: Standard Library Design
Chapter 49: Functional Abstraction
- 49.1 itertools(itertools 用 C-level iterator 对象封装组合、截断、分组和笛卡尔积等惰性序列处理)
- 49.2 functools(functools 提供 cached_property、lru_cache、partial、wraps、singledispatch 等 callable 包装和缓存工具)
- 49.3 lazy evaluation(惰性求值把数据生产推迟到
next(),能降低内存峰值,也会改变错误触发时间) - 49.4 iterator pipeline(iterator pipeline 用一串 iterator 对象传递数据,每一步都需要考虑消费次数、短路和异常传播)
- 49.5 higher-order function(高阶函数把行为作为对象传递,常见成本来自闭包、partial、descriptor binding 和 wrapper 层)
- 49.6 callable adaptation(callable adaptation 会把函数、method、partial、descriptor、decorator 和 singledispatch 统一成可调用入口)
- 49.7 generator composition(generator composition 通过
yield from、generator expression、chain 等方式组合惰性数据流) - 49.8 stream processing(stream processing 需要处理 backpressure、一次性消费、资源关闭和异常时的 cleanup)
Chapter 50: Runtime Introspection
- 50.1 inspect(inspect 读取 function、class、module、frame、signature、source 等对象元数据,支撑调试和框架自省)
- 50.2 runtime introspection(runtime introspection 通过
dir、getattr、__dict__、MRO、descriptor 和 annotation 观察对象结构) - 50.3 signature(signature 还原 callable 参数种类、默认值、annotation、varargs 和 binding 规则)
- 50.4 frame inspection(frame inspection 能读取调用栈、locals、globals、code object 和当前行号,也可能延长 frame 生命周期)
- 50.5 source inspection(source inspection 依赖文件路径、linecache、loader、module metadata 和运行环境保留的源码)
- 50.6 object metadata(
__name__、__qualname__、__module__、__annotations__、__doc__、__dict__构成对象可观察身份) - 50.7 runtime reflection(reflection 可以动态发现能力、构造调用、注册插件和生成文档,同时会削弱静态分析稳定性)
- 50.8 dynamic analysis(dynamic analysis 通过 trace/profile hook、frame、dis、inspect 和 logging 捕捉真实运行路径)
Chapter 51: Typing and Runtime Boundary
- 51.1 typing, Generic, TypeVar, and Protocol(说明 typing 抽象如何表达静态类型关系)
- 51.2 TypedDict and runtime data shape(整理结构化字典类型和运行时对象之间的边界)
- 51.3 Static vs runtime typing(说明类型检查器结论和 runtime 行为之间的差异)
- 51.4 Annotation evaluation and generic alias(追踪 annotation 在不同版本中的求值和保留方式)
- 51.5 Runtime typing cost and boundary(提炼何时使用运行时校验、何时依赖静态类型的判断方法)
Chapter 52: Context Managers and Resource Cleanup Architecture
- 52.1 contextlib(contextlib 把生成器函数、回调栈和 decorator 包装成统一 context manager 工具层)
- 52.2 ExitStack(ExitStack 允许运行时动态注册多个 context manager 和 cleanup callback,并按反向顺序退出)
- 52.3 AsyncExitStack(AsyncExitStack 同时管理 async context manager、async callback 和 awaitable cleanup)
- 52.4 deterministic cleanup(deterministic cleanup 让文件、锁、事务、临时状态在正常返回和异常路径上都有稳定释放点)
- 52.5 context composition(context composition 需要处理多个资源获取失败时,已获取资源按正确顺序释放)
- 52.6 resource lifetime(资源 lifetime 要标出 owner、borrower、transfer、release、close、cancel 和 finalizer 的责任边界)
- 52.7 exception-safe cleanup(exception-safe cleanup 需要保证清理异常、原始异常、suppression 和 finally 顺序都可分析)
Chapter 53: Serialization Boundary
- 53.1 json(json 只表达有限数据类型,适合跨语言数据交换,需要显式处理 datetime、decimal、bytes 和自定义对象)
- 53.2 pickle(pickle 保存 Python 对象图和类路径,功能强但执行加载逻辑,适合可信边界内持久化)
- 53.3 marshal(marshal 服务 CPython 内部字节码等低层格式,版本耦合强,适合读懂
.pyc相关边界) - 53.4 object graph serialization(对象图序列化需要处理循环引用、共享引用、类型身份、版本演进和反序列化安全)
- 53.5 security implications(整理 security implications 的触发条件、可见表现、运行时成本和边界)
- 53.6 protocol version(pickle protocol version 决定 opcode、buffer 支持、兼容范围和跨版本读取能力)
- 53.7 object identity preservation(pickle 可以保留对象共享关系,json 通常只保留值结构,这会影响缓存和恢复语义)
- 53.8 binary serialization(二进制序列化要处理 endian、alignment、buffer ownership、zero-copy 和 native boundary)
Chapter 54: Filesystem and OS Abstraction
- 54.1 pathlib(pathlib 把路径字符串包装成对象模型,区分 PurePath 语义和真实 filesystem 操作)
- 54.2 os(os 模块暴露进程、文件描述符、权限、环境变量和系统调用风格接口)
- 54.3 sys(sys 暴露解释器状态、模块表、路径、argv、exception info、trace hook 和 runtime 配置)
- 54.4 filesystem abstraction(filesystem abstraction 要处理路径编码、权限、符号链接、atomic rename、临时文件和跨平台差异)
- 54.5 process abstraction(process abstraction 连接 pid、exit code、signal、subprocess、stdin/stdout/stderr 和环境变量)
- 54.6 environment variable(environment variable 是进程启动时继承的字符串配置,影响 import path、locale、runtime flag 和部署行为)
- 54.7 file descriptor(file descriptor 是 OS 级资源句柄,Python file object 在其上叠加 buffering、encoding 和 context manager)
- 54.8 path semantics(路径语义涉及 relative/absolute、cwd、home、case sensitivity、separator、drive、URI 和 sandbox)
Chapter 55: Concurrency Abstraction
- 55.1 threading(threading 封装 OS thread、GIL 约束、lock、condition、local storage 和生命周期管理)
- 55.2 multiprocessing(multiprocessing 用进程隔离绕开 GIL,代价是启动、pickle、IPC、共享内存和资源回收)
- 55.3 asyncio(asyncio 用 event loop、Task、Future、transport/protocol 和 coroutine 调度协作式并发)
- 55.4 concurrent.futures(futures 把线程池、进程池和异步结果包装成统一 submit/result/cancel 接口)
- 55.5 synchronization primitives(Lock、RLock、Semaphore、Condition、Event、Queue 分别解决互斥、通知、容量和跨线程通信)
- 55.6 process isolation(进程隔离让内存、GIL、崩溃影响和权限边界分离,同时引入序列化和 IPC 成本)
- 55.7 executor abstraction(executor 把任务提交、worker 生命周期、结果获取、异常传播和 shutdown 包装成调度边界)
- 55.8 async abstraction(async abstraction 需要关注取消、backpressure、任务泄漏、上下文传播和阻塞调用进入 event loop 的后果)
Part 11: Python C API
Chapter 56: Python C API Entry Points and Runtime Contract
- 56.1 PyObject and PyTypeObject as C API roots(说明 C API 如何通过 PyObject 和 PyTypeObject 接入 Python 对象模型)
- 56.2 Ownership model and reference ownership(整理 new、borrowed、strong reference 和 reference leak 的边界)
- 56.3 Error handling and exception indicator(追踪 C API 如何用返回值和 exception indicator 表达失败)
- 56.4 Argument parsing and return convention(说明参数解析、返回对象和错误路径的责任)
- 56.5 Python C API checklist(提炼写 C 扩展时对象、引用、异常和类型检查的顺序)
Chapter 57: Extension Type System
- 57.1 Extension type, heap type, and static type(说明扩展类型如何进入 Python type system)
- 57.2 Slot and method table(整理 slot、method table、member table 和 getset definition 的分发表面)
- 57.3 Module init and capsule(追踪模块初始化、capsule 和跨扩展共享对象)
- 57.4 Lifecycle and ownership boundary(说明扩展对象创建、析构和引用责任)
- 57.5 Extension type checklist(提炼实现扩展类型时类型对象、slot、成员和错误处理的检查点)
Chapter 58: Embedding and Interop
- 58.1 embedding Python(embedding 把 Python runtime 放入宿主进程,需要管理初始化、配置、GIL、module path 和 shutdown)
- 58.2 runtime embedding(宿主程序要决定解释器生命周期、线程进入 Python 的方式、异常回传和多解释器隔离)
- 58.3 native interop(native interop 连接 C/C++ 数据结构、Python object、异常、引用计数和调用约定)
- 58.4 buffer sharing(buffer sharing 通过 Py_buffer、memoryview、NumPy-like protocol 减少复制,同时要求明确释放和写权限)
- 58.5 C boundary cost(整理 C boundary cost 的触发条件、可见表现、运行时成本和边界)
- 58.6 interpreter lifecycle(interpreter lifecycle 包括 preinit、config、initialize、import bootstrap、thread state、finalize 和资源析构顺序)
- 58.7 embedded runtime(embedded runtime 需要把 Python 错误、日志、stdout/stderr、memory allocator 和 signal 行为映射回宿主系统)
- 58.8 extension boundary(extension boundary 定义 native code 何时持有 GIL、谁拥有引用、如何返回错误、如何处理崩溃风险)
Chapter 59: Reference Ownership and Error Path Discipline
- 59.1 New, Borrowed, and Strong References(区分 C API 返回对象时的引用所有权和释放责任)
- 59.2 Py_INCREF, Py_DECREF, and Lifetime Transfer(追踪引用计数变化如何表达对象生命周期和所有权转移)
- 59.3 Error Indicator and Return Convention(整理 C API 通过 NULL、-1、exception indicator 表达失败的路径)
- 59.4 Cleanup Order and Leak Prevention(说明多对象创建失败时的释放顺序和错误恢复边界)
- 59.5 C API Error Path Checklist(给出从引用获取、异常设置、释放顺序到返回值的检查顺序)
Chapter 60: Stable ABI, Limited API, and Extension Compatibility
- 60.1 CPython API Surface and ABI Surface(区分源码级 API、二进制 ABI、internal API 和 public API 的边界)
- 60.2 Limited API and Stable ABI Goals(说明 limited API 如何换取跨版本二进制兼容能力)
- 60.3 Internal Headers and Implementation Coupling(整理依赖内部结构时带来的版本风险和维护成本)
- 60.4 Wheels, Platform Tags, and Distribution Boundary(追踪扩展模块如何通过 wheel tag、平台 ABI 和 Python 版本进入安装路径)
- 60.5 Extension Compatibility Checklist(给出从 API 选择、ABI 目标、构建产物到发布约束的检查顺序)
Chapter 61: Buffer Protocol, Capsules, and Native Boundary Design
- 61.1 Buffer Protocol as Binary Sharing Contract(说明 buffer protocol 如何让 Python 对象暴露连续或分片内存视图)
- 61.2 Py_buffer Lifetime and Release Discipline(追踪 Py_buffer 获取、使用和释放时的对象生命周期关系)
- 61.3 Capsule as Native Pointer Boundary(整理 PyCapsule 如何在扩展之间传递 native pointer 和析构责任)
- 61.4 Crossing the Native Boundary Costs State and Safety(说明 native interop 如何引入复制、锁、异常转换和崩溃边界)
- 61.5 Native Boundary Design Checklist(给出从内存所有权、异常转换、GIL 状态到资源释放的检查顺序)
Part 12: CPython Source Reading
Chapter 62: CPython Source Tree
- 62.1
Objects/(Objects/承载核心对象实现,例如 type、dict、list、unicode、function、descriptor 和 GC 参与对象) - 62.2
Python/(Python/承载解释器执行、编译、import、runtime 初始化、ceval、symtable 和错误处理等核心逻辑) - 62.3
Include/(Include/暴露 C API、对象布局声明、宏、slot、runtime state 结构和 public/internal header 边界) - 62.4
Parser/(Parser/负责 grammar、tokenizer、PEG parser、AST 入口和语法错误定位) - 62.5
Modules/(Modules/放置内置扩展模块、C 实现标准库能力和平台相关模块) - 62.6
Lib/(Lib/是 Python 实现标准库,能看到 importlib、asyncio、contextlib、inspect 等高层抽象如何组织) - 62.7 startup path(startup path 串起配置解析、runtime 初始化、path config、import bootstrap、main module 执行)
- 62.8 runtime bootstrap(runtime bootstrap 建立内置类型、builtins、sys module、import system、thread state 和初始 interpreter state)
Chapter 63: typeobject.c
- 63.1 type system(typeobject.c 展示 type 创建、metaclass 调用、slot 初始化、MRO 缓存和类型对象生命周期)
- 63.2 descriptor lookup(attribute lookup 会按 data descriptor、instance dict、non-data descriptor、class attribute、fallback 的顺序处理)
- 63.3 method binding(函数作为 descriptor 被读取时生成 bound method,把 instance 绑定成第一个参数)
- 63.4 MRO logic(C3 linearization 把继承图转换为方法查找顺序,并在 class creation 时校验一致性)
- 63.5 slot dispatch(numeric、sequence、mapping、call、getattro 等 slot 把 Python 操作连接到类型级 C 函数指针)
- 63.6 special method lookup(special method 常从类型上查找,绕过部分实例属性路径,解释运算符和协议调用的特殊行为)
Chapter 64: dictobject.c
- 64.1 compact dict(compact dict 把 sparse index 和 dense entries 分离,保留插入顺序并降低内存占用)
- 64.2 probing algorithm(probing 使用 hash、perturb、empty/dummy slot 处理冲突、删除和查找终止)
- 64.3 key-sharing dict(实例 dict 可以共享 key table,只保存各实例不同 value,降低大量对象的属性存储成本)
- 64.4 dict resizing(resize 根据填充率和 dummy slot 状态扩容或重建,影响插入成本和内存峰值)
- 64.5 hash strategy(hash、equality、randomization、string hash cache 共同决定 dict 查找正确性和攻击面)
- 64.6 globals lookup optimization(globals/builtins lookup 会被版本 tag、inline cache、specialized opcode 加速)
Chapter 65: listobject.c and unicodeobject.c
- 65.1 dynamic array(listobject.c 展示 over-allocation、resize、append、insert、slice 和 freelist 如何支撑 list 性能)
- 65.2 unicode representation(unicodeobject.c 使用 kind、compact、ASCII flag、canonical data 表示不同字符范围的字符串)
- 65.3 compact unicode(compact unicode 把对象头和字符数据放在连续内存中,降低访问和分配成本)
- 65.4 memory optimization(list over-allocation、unicode compact layout、interning、freelist 都服务常见对象的内存/速度权衡)
- 65.5 string caching(string interning、hash cache、identifier cache 会影响名字查找、dict key 和内存观察)
Chapter 66: descrobject.c and funcobject.c
- 66.1 descriptor implementation(descrobject.c 展示 getset/member/wrapper/property 等 descriptor 如何把 C 字段和 Python attribute 连接)
- 66.2 function object(funcobject.c 中 function object 持有 code、globals、defaults、kwdefaults、closure、annotations 和 vectorcall 入口)
- 66.3 method object(method object 保存 function 与 self/class 的绑定关系,并参与调用路径)
- 66.4 vectorcall(vectorcall 用连续参数数组和 flags 减少 tuple/dict 临时对象,优化高频调用)
- 66.5 callable dispatch(callable dispatch 会经过 tp_call、vectorcall slot、method binding、argument parsing 和错误返回约定)
- 66.6 property implementation(property 用 fget、fset、fdel、doc 组合成 data descriptor,解释 attribute 访问如何转为函数调用)
Chapter 67: genobject.c and frameobject.c
- 67.1 generator object(genobject.c 展示 generator 如何保存 code/frame 状态、yield value、running flag 和关闭逻辑)
- 67.2 coroutine object(coroutine object 与 generator 共享暂停机制,同时加入 awaitable 语义和 coroutine 状态检查)
- 67.3 suspended frame(suspended frame 保留 instruction pointer、locals、value stack 和异常状态,等待下一次 resume)
- 67.4 frame persistence(frame 被 generator/coroutine/traceback/inspect 持有时会延长局部对象生命周期)
- 67.5 async runtime relation(asyncio Task 驱动 coroutine resume,异常、取消和返回值通过 Future/Task 状态传播)
Chapter 68: compile.c and symtable.c
- 68.1 compiler pipeline(compiler pipeline 把 AST、symbol table、CFG、basic block、bytecode 和 exception table 串成源码到指令的转换链)
- 68.2 symbol analysis(symtable.c 判断 local、global、free、cell、nonlocal、comprehension scope,决定后续 opcode 选择)
- 68.3 bytecode generation(compile.c 将 AST 节点翻译为 stack effect、jump、const/name table 和 opcode sequence)
- 68.4 AST traversal(AST traversal 保留语义结构、source location、作用域信息,并驱动语法特性进入编译阶段)
- 68.5 compiler optimization(compiler optimization 会处理常量、跳转、basic block、stack depth 和版本相关指令形态)
Chapter 69: ceval.c
- 69.1 evaluation loop(ceval.c 的 evaluation loop 负责逐条执行 bytecode、维护 value stack,并把调用/异常/yield 交给对应路径)
- 69.2 opcode dispatch(opcode dispatch 通过 switch/computed goto/specialized instruction 将当前 opcode 路由到处理代码)
- 69.3 specialization(specialization 利用 inline cache 和 runtime feedback 替换通用 opcode,优化常见类型路径)
- 69.4 frame execution(frame execution 管理 fast locals、stack、block/exception state、return value 和 traceback 连接)
- 69.5 runtime state(runtime state 包括 interpreter、thread、gil、pending calls、signals、recursion limit 和 eval breaker flags)
- 69.6 eval breaker(eval breaker 让解释器在安全检查点处理 signal、pending call、GIL scheduling 和 async exception)
Chapter 70: gcmodule.c and obmalloc.c
- 70.1 cyclic gc(gcmodule.c 通过 tracking、generation、traverse、clear 处理引用环和 container object)
- 70.2 generation management(generation 管理对象年龄、collection 阈值、promotion 和 full collection 成本)
- 70.3 object tracking(只有需要 GC 参与的 container object 被 tracking,atomic-like 对象通常走引用计数即可)
- 70.4 pymalloc(obmalloc.c 通过 arena/pool/block、size class、free list 管理小对象内存)
- 70.5 arena/pool/block(arena 来自系统 allocator,pool 服务同一 size class,block 是具体小对象分配单元)
- 70.6 object reuse(object reuse 会影响内存峰值、
id()重用、泄漏排查和性能曲线)
Chapter 71: importlib asyncio and contextlib
- 71.1
import system(importlib 展示 finder、loader、ModuleSpec、sys.modules cache、package path 和 lazy/error 边界) - 71.2 async runtime(asyncio 展示 event loop、Task、Future、transport、callback、cancellation 和 backpressure 的标准库组织方式)
- 71.3 context manager abstraction(contextlib 展示 generator-based manager、ExitStack、async cleanup 如何统一资源生命周期)
- 71.4 stdlib design pattern(标准库常用 protocol、duck typing、context manager、iterator、adapter、cache 和 wrapper 组织抽象)
Part 13: Runtime Evolution
Chapter 72: Parser and Compiler Pipeline Evolution
- 72.1 PEG Parser and Grammar Evolution(整理 parser 技术变化如何影响语法表达、错误定位和编译入口)
- 72.2 Symbol Analysis and Bytecode Generation Changes(说明 symbol table、compiler state 和 bytecode generation 如何随版本演进)
- 72.3 Exception Table and Position Metadata(追踪异常表、源码位置和调试信息如何改变错误观察方式)
- 72.4 Version-Sensitive Bytecode Reading(给出跨版本阅读 bytecode、opcode 和 dis 输出的边界)
- 72.5 Compiler Evolution Checklist(给出从语法、AST、symbol table 到 bytecode 的版本检查顺序)
Chapter 73: Adaptive Interpreter, Specialization, and JIT Direction
- 73.1 Adaptive Interpreter as Runtime Feedback Loop(说明解释器如何用真实运行反馈选择 specialized opcode)
- 73.2 Inline Cache and Deoptimization Boundary(追踪 cache 命中、假设失效和回退路径之间的关系)
- 73.3 Copy-and-Patch JIT Direction(整理 JIT 方向如何把 specialization、模板代码和运行时状态连接起来)
- 73.4 Performance Evidence and Semantic Stability(说明性能优化如何保持 Python 语义并改变可观察成本)
- 73.5 Runtime Optimization Reading Checklist(给出从 opcode、cache、对象类型到性能现象的分析顺序)
Chapter 74: Immortal Objects, Memory Model, and Free-Threaded Python
- 74.1 Immortal Objects and Refcount Strategy(说明 immortal object 如何改变引用计数更新和共享对象成本)
- 74.2 Atomic Reference Counting and Memory Synchronization(整理 free-threaded Python 对引用计数、锁和内存同步的要求)
- 74.3 Object Layout and Allocator Evolution(追踪对象布局、allocator、GC tracking 和缓存策略的演进边界)
- 74.4 Compatibility Cost of Runtime Parallelism(说明并行运行时如何影响 C API、扩展模块和对象共享习惯)
- 74.5 Memory Evolution Checklist(给出从对象生命周期、共享状态、锁策略到扩展兼容性的检查顺序)
Chapter 75: Subinterpreters, Isolation, and Runtime Parallelism
- 75.1 Interpreter State and Isolation Boundary(说明 PyInterpreterState 如何承载运行时状态和隔离边界)
- 75.2 Per-Interpreter GIL and Object Ownership(追踪 per-interpreter GIL 如何改变并发能力和对象跨解释器共享)
- 75.3 Channel, Serialization, and Data Transfer(说明解释器之间传递数据时的复制、序列化和所有权关系)
- 75.4 Embedding and Plugin Runtime Design(说明 subinterpreter 如何影响插件系统、嵌入式运行时和服务隔离)
- 75.5 Parallel Runtime Checklist(给出从 interpreter state、对象所有权、通信方式到失败边界的检查顺序)
Chapter 76: Reading Future CPython Changes with Stable Models
- 76.1 Stable Models Across Version Changes(把 execution、object、protocol、compiler 和 memory 模型作为阅读新版本的稳定骨架)
- 76.2 What Changes Across Versions(整理 opcode、parser、C API、allocator、GIL、JIT 和 stdlib 行为中的版本敏感点)
- 76.3 What Remains Semantically Stable(说明 name binding、object identity、protocol dispatch、exception propagation 等语义边界的稳定性)
- 76.4 Source Reading Without Local Source Assumption(给出通过公开材料、文档、release note 和小示例追踪变化的路径)
- 76.5 Runtime Evolution Synthesis(把本书的语义模型、对象模型和源码阅读方法收束成后续跟踪 CPython 的判断框架)