René's URL Explorer Experiment
Title: Return precomputed bytes for single-byte indexed fields by DicksonWu654 · Pull Request #305 · python-hyper/hpack · GitHub
Open Graph Title: Return precomputed bytes for single-byte indexed fields by DicksonWu654 · Pull Request #305 · python-hyper/hpack
X Title: Return precomputed bytes for single-byte indexed fields by DicksonWu654 · Pull Request #305 · python-hyper/hpack
Description: Every header that is already in the static or dynamic table is encoded by Encoder._encode_indexed(), which calls encode_integer() (building a bytearray), sets the top bit and copies the result to bytes. Any index below 127 fits in the 7-bit prefix and always encodes to the single byte 0x80 | index, so this looks those up in a 127-entry tuple of precomputed bytes instead.
Other values and types (127 and above, bool, negative numbers, non-ints) still go through encode_integer(), with the same output and errors.
When the hpack logger has DEBUG enabled, the existing path is used as well, so the Encoding %d with %d bits records (including their funcName) are unchanged.
The table adds 127 one-byte bytes objects at import time.
Benchmarks
Each workload runs header blocks through Encoder.encode() and, for *_roundtrip, Decoder.decode(). browser_mixed alternates 16 browser-like requests and 16 responses; repeated_requests sends one request 16 times, so after the first block every field is indexed; long_cookie is 16 requests whose cookie is about 1.2 KB; no_huffman_encode is browser_mixed with huffman=False; fixture_stories_roundtrip replays the first four stories of the hpack-test-case fixtures in tests/.
master and this branch were imported side by side in the same interpreter and timed in alternating ~20 ms CPU-time blocks (40 rounds in each of 6 processes, pinned to one core). The table shows the median per-round speedup with a 95% bootstrap interval. The machine was shared with other work, so the absolute times are only indicative.
Workload
CPython 3.12.3 master → branch (µs)
CPython 3.12.3 speedup
CPython 3.14.8 speedup
browser_mixed_encode
1,794.3 → 1,695.9
1.06x [1.03, 1.08]
1.06x [1.05, 1.08]
browser_mixed_roundtrip
3,938.6 → 3,755.2
1.04x [1.02, 1.06]
1.02x [1.01, 1.04]
repeated_requests_encode
414.7 → 337.5
1.24x [1.22, 1.26]
1.23x [1.22, 1.25]
repeated_requests_roundtrip
953.5 → 872.3
1.10x [1.07, 1.13]
1.11x [1.09, 1.12]
responses_decode
669.4 → 666.5
1.01x [0.99, 1.03]
1.00x [0.99, 1.02]
long_cookie_encode
7,183.9 → 7,029.2
1.00x [0.99, 1.02]
1.01x [1.00, 1.02]
long_cookie_roundtrip
12,117.6 → 11,750.4
1.02x [1.00, 1.03]
1.00x [0.98, 1.01]
no_huffman_encode
1,028.6 → 944.7
1.10x [1.09, 1.12]
1.09x [1.07, 1.10]
fixture_stories_roundtrip
2,086.2 → 1,987.1
1.06x [1.04, 1.08]
1.07x [1.05, 1.08]
Behaviour
New tests: the indexed encoding at the 7-bit prefix boundary (0, 1, 126, 127, 128, 255, True), invalid values, and a DEBUG-logging round trip that checks the redaction of sensitive values and that the integer-encoding records still come from encode_integer.
pytest passes with 100% statement and branch coverage on CPython 3.11, 3.12, 3.13 and 3.14; ruff check src/ and mypy src/ (the lint tox env) pass.
I also compared master and this branch on 1,500 random encoder/decoder sessions per interpreter (CPython 3.11 and 3.14), including repeated headers so the dynamic table is hit, table size changes, sensitive headers and direct _encode_indexed() calls with indices from 0 to 200. The encoded bytes, decoded headers, exceptions and, with DEBUG logging enabled, every log record were identical.
🤖 Generated with Claude Code
Open Graph Description: Every header that is already in the static or dynamic table is encoded by Encoder._encode_indexed(), which calls encode_integer() (building a bytearray), sets the top bit and copies the result to b...
X Description: Every header that is already in the static or dynamic table is encoded by Encoder._encode_indexed(), which calls encode_integer() (building a bytearray), sets the top bit and copies the result to b...
Opengraph URL: https://github.com/python-hyper/hpack/pull/305
X: @github
direct link
Domain: github.com
IPv4 address: 140.82.114.3
| 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:50d722f7-59bb-ea30-815f-c7be00057857 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B34C:5D41F:222B352:2EB6912:6B0733DF |
| html-safe-nonce | cd438fbb2b82c7a29a7a8e8369d10c8495e319fbcfb0807685485f616e993b93 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzRDOjVENDFGOjIyMkIzNTI6MkVCNjkxMjo2QjA3MzNERiIsInZpc2l0b3JfaWQiOiI0ODA5MTEyMDM0NTkzOTQ0NTQ0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8662b951ae1b17e481e79e04a12ecfd7ad64f8a7874a0f4d5333064574d4bf36 |
| hovercard-subject-tag | pull_request:5185682259 |
| 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 | ///pull_requests/show/files |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-hyper/hpack/pull/305/files |
| twitter:image | https://avatars.githubusercontent.com/u/33645481?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/33645481?s=400&v=4 |
| og:image:alt | Every header that is already in the static or dynamic table is encoded by Encoder._encode_indexed(), which calls encode_integer() (building a bytearray), sets the top bit and copies the result to b... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2a60952cad7efb2604ea85e500208f51c1ec1943aa260ac605c13eb46a1ed83b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-hyper/hpack git https://github.com/python-hyper/hpack.git |
| octolytics-dimension-user_id | 13035907 |
| octolytics-dimension-user_login | python-hyper |
| octolytics-dimension-repository_id | 33873218 |
| octolytics-dimension-repository_nwo | python-hyper/hpack |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 33873218 |
| octolytics-dimension-repository_network_root_nwo | python-hyper/hpack |
| 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 | 345c27626db08417fdfc84278a4415ae9a48d8f3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Skip to content | https://github.com/python-hyper/hpack/pull/305/files#start-of-content |
| https://github.com/ |
| Sign in | https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-hyper%2Fhpack%2Fpull%2F305%2Ffiles |
| GitHubRepository hosting, code review, and collaboration | https://github.com/platform |
| CopilotAI coding agent for tasks, projects, and automated work | https://github.com/features/copilot |
| ActionsCI/CD and automation | https://github.com/features/actions |
| Code QualityQuality analysis, fixes, and enforcement | https://github.com/features/code-quality |
| CodespacesCloud development environments | https://github.com/features/codespaces |
| Code SecurityVulnerability detection and remediation | https://github.com/security/advanced-security/code-security |
| Secret ProtectionSecret scanning and leak prevention | https://github.com/security/advanced-security/secret-protection |
| All Features | https://github.com/features |
| Documentation | https://docs.github.com/en |
| Training | https://learn.github.com/skills |
| Certifications | https://learn.github.com/credentials |
| Build with Copilot | https://github.com/features/ai |
| Customize Copilot | https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview |
| Integrations | https://github.com/marketplace |
| Trending repos | https://github.com/trending |
| GitHub Sponsors | https://github.com/open-source/sponsors |
| Developer articles | https://github.com/resources/articles |
| ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place. | https://github.blog/changelog/ |
| Enterprises | https://github.com/enterprise |
| Team | https://github.com/team |
| Startups | https://github.com/enterprise/startups |
| Nonprofits | https://github.com/solutions/industry/nonprofits |
| Healthcare | https://github.com/solutions/industry/healthcare |
| Financial services | https://github.com/solutions/industry/financial-services |
| Manufacturing | https://github.com/solutions/industry/manufacturing |
| Government | https://github.com/solutions/industry/government |
| See all industries | https://github.com/solutions/industry |
| Why GitHub | https://github.com/why-github |
| Customer Stories | https://github.com/customer-stories |
| Business insights | https://github.com/solutions/executive-insights |
| Trust Center | https://github.com/trust-center |
| GitHub Advanced SecurityEnterprise-grade code security | https://github.com/security/advanced-security |
| Copilot for businessEnterprise-grade AI features | https://github.com/features/copilot/copilot-business |
| Premium SupportEnterprise-grade 24/7 support | https://github.com/enterprise/premium-support |
| Documentation | https://docs.github.com/en |
| Resource center | https://github.com/resources |
| Blog | https://github.blog/ |
| Events & webinars | https://github.com/resources/events |
| Community Forum | https://github.com/orgs/community/discussions |
| Customer Stories | https://github.com/customer-stories |
| Integrations | https://github.com/marketplace |
| Customer support | https://help.github.com/ |
| Training | https://learn.github.com/skills |
| GitHub Status | https://www.githubstatus.com/ |
| About | https://github.com/about |
| Partners | https://github.com/partners |
| Changelog | https://github.blog/changelog/ |
| GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub. | https://githubuniverse.com/ |
| Pricing | https://github.com/pricing |
| Sign in | https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-hyper%2Fhpack%2Fpull%2F305%2Ffiles |
| Sign up | https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python-hyper%2Fhpack |
| Reload | https://github.com/python-hyper/hpack/pull/305/files |
| Reload | https://github.com/python-hyper/hpack/pull/305/files |
| Reload | https://github.com/python-hyper/hpack/pull/305/files |
| python-hyper | https://github.com/python-hyper |
| hpack | https://github.com/python-hyper/hpack |
| Code | https://github.com/python-hyper/hpack |
| Issues | https://github.com/python-hyper/hpack/issues |
| Pull requests7 (7) | https://github.com/python-hyper/hpack/pulls |
| Actions | https://github.com/python-hyper/hpack/actions |
| Security and quality1 (1) | https://github.com/python-hyper/hpack/security |
| Insights | https://github.com/python-hyper/hpack/insights |
| Sign up for GitHub
| https://github.com/signup?return_to=%2Fpython-hyper%2Fhpack%2Fissues%2Fnew%2Fchoose |
| terms of service | https://docs.github.com/terms |
| privacy statement | https://docs.github.com/privacy |
| Sign in | https://github.com/login?return_to=%2Fpython-hyper%2Fhpack%2Fissues%2Fnew%2Fchoose |
| DicksonWu654 | https://github.com/DicksonWu654 |
| python-hyper:master | https://github.com/python-hyper/hpack/tree/master |
| DicksonWu654:perf/indexed-field-bytes | https://github.com/DicksonWu654/hpack/tree/perf/indexed-field-bytes |
|
Conversation
0
| https://github.com/python-hyper/hpack/pull/305 |
|
Commits
1
| https://github.com/python-hyper/hpack/pull/305/commits |
|
Checks
0
| https://github.com/python-hyper/hpack/pull/305/checks |
|
Files changed
| https://github.com/python-hyper/hpack/pull/305/files |
| Please reload this page | https://github.com/python-hyper/hpack/pull/305/files |
|
Return precomputed bytes for single-byte indexed fields
| https://github.com/python-hyper/hpack/pull/305/files#top |
|
Show all changes
1 commit
| https://github.com/python-hyper/hpack/pull/305/files |
|
f6b554d
Return precomputed bytes for single-byte indexed fields
DicksonWu654 Nov 6, 2026
| https://github.com/python-hyper/hpack/pull/305/commits/f6b554de435a27aa2a083cc11602c4fdbe6fae15 |
|
Clear filters
| https://github.com/python-hyper/hpack/pull/305/files |
| Please reload this page | https://github.com/python-hyper/hpack/pull/305/files |
| Please reload this page | https://github.com/python-hyper/hpack/pull/305/files |
|
CHANGELOG.rst
| https://github.com/python-hyper/hpack/pull/305/files#diff-2c623f3c6a917be56c59d43279244996836262cb1e12d9d0786c9c49eef6b43c |
|
hpack.py
| https://github.com/python-hyper/hpack/pull/305/files#diff-311bdeef42d63e07b32935c24dc7c3e0f57f90ea54b357673d0fa0a7d8a23b5e |
|
test_hpack.py
| https://github.com/python-hyper/hpack/pull/305/files#diff-dc78395f3ddc698fad2eec94932df306aa317f3901921ce52c033cd2c6d6d6a0 |
| CHANGELOG.rst | https://github.com/python-hyper/hpack/pull/305/files#diff-2c623f3c6a917be56c59d43279244996836262cb1e12d9d0786c9c49eef6b43c |
|
View file
| https://github.com/python-hyper/hpack/blob/f6b554de435a27aa2a083cc11602c4fdbe6fae15/CHANGELOG.rst |
|
Open in desktop
| https://desktop.github.com |
| https://github.co/hiddenchars |
| https://github.com/python-hyper/hpack/pull/305/{{ revealButtonHref }} |
|
| https://github.com/python-hyper/hpack/pull/305/files#diff-2c623f3c6a917be56c59d43279244996836262cb1e12d9d0786c9c49eef6b43c |
|
| https://github.com/python-hyper/hpack/pull/305/files#diff-2c623f3c6a917be56c59d43279244996836262cb1e12d9d0786c9c49eef6b43c |
| src/hpack/hpack.py | https://github.com/python-hyper/hpack/pull/305/files#diff-311bdeef42d63e07b32935c24dc7c3e0f57f90ea54b357673d0fa0a7d8a23b5e |
|
View file
| https://github.com/python-hyper/hpack/blob/f6b554de435a27aa2a083cc11602c4fdbe6fae15/src/hpack/hpack.py |
|
Open in desktop
| https://desktop.github.com |
| https://github.co/hiddenchars |
| https://github.com/python-hyper/hpack/pull/305/{{ revealButtonHref }} |
|
| https://github.com/python-hyper/hpack/pull/305/files#diff-311bdeef42d63e07b32935c24dc7c3e0f57f90ea54b357673d0fa0a7d8a23b5e |
|
| https://github.com/python-hyper/hpack/pull/305/files#diff-311bdeef42d63e07b32935c24dc7c3e0f57f90ea54b357673d0fa0a7d8a23b5e |
|
| https://github.com/python-hyper/hpack/pull/305/files#diff-311bdeef42d63e07b32935c24dc7c3e0f57f90ea54b357673d0fa0a7d8a23b5e |
|
| https://github.com/python-hyper/hpack/pull/305/files#diff-311bdeef42d63e07b32935c24dc7c3e0f57f90ea54b357673d0fa0a7d8a23b5e |
| tests/test_hpack.py | https://github.com/python-hyper/hpack/pull/305/files#diff-dc78395f3ddc698fad2eec94932df306aa317f3901921ce52c033cd2c6d6d6a0 |
|
View file
| https://github.com/python-hyper/hpack/blob/f6b554de435a27aa2a083cc11602c4fdbe6fae15/tests/test_hpack.py |
|
Open in desktop
| https://desktop.github.com |
| https://github.co/hiddenchars |
| https://github.com/python-hyper/hpack/pull/305/{{ revealButtonHref }} |
|
| https://github.com/python-hyper/hpack/pull/305/files#diff-dc78395f3ddc698fad2eec94932df306aa317f3901921ce52c033cd2c6d6d6a0 |
|
| https://github.com |
| Terms | https://docs.github.com/site-policy/github-terms/github-terms-of-service |
| Privacy | https://docs.github.com/site-policy/privacy-policies/github-privacy-statement |
| Security | https://github.com/security |
| Status | https://www.githubstatus.com/ |
| Community | https://github.community/ |
| Docs | https://docs.github.com/ |
| Contact | https://support.github.com?tags=dotcom-footer |
Response headers:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width
URLs of crawlers that visited me.