Title: Document how to add a new bytecode specialization by shreyash-bhosale · Pull Request #1932 · python/devguide · GitHub
Open Graph Title: Document how to add a new bytecode specialization by shreyash-bhosale · Pull Request #1932 · python/devguide
X Title: Document how to add a new bytecode specialization by shreyash-bhosale · Pull Request #1932 · python/devguide
Description: Summary Adds a new developer guide at developer-workflow/specialization.rst documenting how to specialize a bytecode instruction in CPython's Specializing Adaptive Interpreter (PEP 659). Motivation Adding a new bytecode specialization requires updates across several disparate subsystems in CPython, including the interpreter DSL in Python/bytecodes.c, inline cache layouts in Include/internal/pycore_code.h, specialization routines in Python/specialize.c, dis metadata in Lib/opcode.py, bytecode magic numbers, and code regeneration. Currently, this knowledge is spread across past PRs and core developer memory. Documenting this workflow in the Developer's Guide provides a clear, step-by-step checklist to lower the barrier for new contributors interested in interpreter optimization. What's Included The new document breaks down the process into an eight-step recipe, using [python/cpython#116385](python/cpython#116385) (specialization of CONTAINS_OP) as a concrete, real-world example: Inline Cache & Header Declarations (Include/internal/pycore_code.h): Struct definition with uint16_t counter, the CACHE_ENTRIES macro, and the function signature. Bytecode DSL & Instruction Families (Python/bytecodes.c): Defining family(), refactoring the base instruction to micro-op op(_OP), adding specializing op(_SPECIALIZE_OP), combining via macro(OP), and writing specialized inst(OP_VARIANT, (unused/N, ...)) cases with DEOPT_IF guards. Specialization Function & Statistics (Python/specialize.c): Registering statistics with add_stat_dict(), implementing type checks, rewriting instr->op.code, updating counter backoff/cooldown, and tracking STAT_INC hits and misses. Internal Fast-Path Helpers: Declaring type-specific C helpers in internal headers when bypassing generic slot dispatch. Disassembler Metadata (Lib/opcode.py): Adding the cache format to _inline_cache_entries for dis. Bytecode Cache Invalidation (Include/internal/pycore_magic_number.h): Bumping MAGIC_NUMBER. Code Generation: Running make regen-all or build.bat --regen. Testing & Benchmarking: Running opcode and disassembly tests, inspecting pystats, and benchmarking with pyperformance. The new page is also registered in developer-workflow/index.rst. Verification Built the documentation locally using Sphinx: make html
Open Graph Description: Summary Adds a new developer guide at developer-workflow/specialization.rst documenting how to specialize a bytecode instruction in CPython's Specializing Adaptive Interpreter (PEP 659). Motiva...
X Description: Summary Adds a new developer guide at developer-workflow/specialization.rst documenting how to specialize a bytecode instruction in CPython's Specializing Adaptive Interpreter (PEP 659). Mo...
Opengraph URL: https://github.com/python/devguide/pull/1932
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:dc630a10-346e-cb7f-3f8d-9bdf043d6ea6 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A33C:F8C5C:301FB2:3CB690:6B01EF55 |
| html-safe-nonce | acd0bd65730f7f0370de5171506472ab26feec6d37d7d2d48c272f115cb42f17 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzNDOkY4QzVDOjMwMUZCMjozQ0I2OTA6NkIwMUVGNTUiLCJ2aXNpdG9yX2lkIjoiNjM1NjI3MjgxNzg0MzA3Mjg1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 116f1b1ae90e766c07f8bbe1e10f073e2a9990068231edae491ddbfa4ef881e8 |
| hovercard-subject-tag | pull_request:4987036597 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/devguide/pull/1932/files |
| twitter:image | https://avatars.githubusercontent.com/u/283447669?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/283447669?s=400&v=4 |
| og:image:alt | Summary Adds a new developer guide at developer-workflow/specialization.rst documenting how to specialize a bytecode instruction in CPython's Specializing Adaptive Interpreter (PEP 659). Motiva... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/devguide git https://github.com/python/devguide.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 63972479 |
| octolytics-dimension-repository_nwo | python/devguide |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63972479 |
| octolytics-dimension-repository_network_root_nwo | python/devguide |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width