~/talk

Bytecode and .pyc files

Talkat Swiss Python Summit 2025 · 2025-10-16..10-17· [python]
links:none on file
slides:none on file

Explains that CPython compiles source to bytecode (about 122 instructions in 3.12) stored in .pyc files under __pycache__ with a magic number and timestamp/hash; shows how to inspect and mutate code with dis, marshal and types.FunctionType, uses code.replace to swap opcodes (example: changing a binary-op yields unexpected numeric results, discovered as BINARY_AND → 2), shows python -m compileall and -O levels (asserts/docstrings removed), and notes ~100 ms startup win for precompiled bytecode and poorer tracebacks if .py files are removed.

AI-written summary · about

  1. 0:00Introduction and speaker intro
  2. 1:10Speaker introduction
  3. 2:39Connectivity check and talk start
  4. 3:00What is Python bytecode
  5. 4:45How Python interpreter works
  6. 6:34Bytecode instructions overview
  7. 8:18Tools for reading bytecode
  8. 11:59Deep dive into bytecode details
  9. 15:18Frames and stacks in Python
  10. 16:46Interpreting bytecode step by step
  11. 20:21Introduction to .pyc files
  12. 22:10Creating and using .pyc files
  13. 23:56Optimizing with .pyc files
  14. 25:50Bytecode optimization levels
  15. 26:34Exception handling in bytecode
  16. 27:40Modifying functions on the fly
  17. 29:10Advanced bytecode manipulation
  18. 31:20Q&A session begins
  19. 31:41Bytecode optimizations explained
  20. 32:24Practical takeaways
  21. 33:28Null values in bytecode
  22. 34:13JIT compilation in Python
  23. 35:15Performance impact of .pyc files
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.