Title: Speed up json.dumps() for small documents · Issue #150820 · python/cpython · GitHub
Open Graph Title: Speed up json.dumps() for small documents · Issue #150820 · python/cpython
X Title: Speed up json.dumps() for small documents · Issue #150820 · python/cpython
Description: json.dumps() runs through the pure-Python iterencode() wrapper on every call, even though the C accelerator does the actual encoding. That wrapper builds a float-formatting helper closure each time it runs, regardless of whether the docu...
Open Graph Description: json.dumps() runs through the pure-Python iterencode() wrapper on every call, even though the C accelerator does the actual encoding. That wrapper builds a float-formatting helper closure each time...
X Description: json.dumps() runs through the pure-Python iterencode() wrapper on every call, even though the C accelerator does the actual encoding. That wrapper builds a float-formatting helper closure each time...
Opengraph URL: https://github.com/python/cpython/issues/150820
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Speed up json.dumps() for small documents","articleBody":"`json.dumps()` runs through the pure-Python `iterencode()` wrapper on every call, even though the C accelerator does the actual encoding. That wrapper builds a float-formatting helper closure each time it runs, regardless of whether the document contains any floats and regardless of whether the fast C path (which never uses the helper) is taken. For the small documents that dominate real traffic, that per-call setup is a measurable slice of the work.\n\nMost JSON crossing a service boundary is small: an API response, a single record, a config fragment. Web frameworks, RPC layers and log shippers encode these short payloads constantly, one per request or record, so the fixed per-call cost adds up.\n\nOver 20 small documents, building the float helper only on the slower Python encoding path makes `json.dumps()` about 8% faster, consistently across float-heavy, mixed and no-float payloads. The win applies to the default build with the C accelerator, since the wrapper that carries this overhead is written in Python.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-150827\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/gaborbernat","@type":"Person","name":"gaborbernat"},"datePublished":"2026-06-02T22:43:24Z","url":"https://github.com/python/cpython/issues/150820"}
| 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 | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:99e02fea-53d5-7c68-85e0-5cd2f98ce78c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E1F4:172B92:35EA421:47D2025:6B020955 |
| html-safe-nonce | 3039bd0cf6b41f993670cd29ac60fa497f27d7d8854d1a255d0156428420f442 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMUY0OjE3MkI5MjozNUVBNDIxOjQ3RDIwMjU6NkIwMjA5NTUiLCJ2aXNpdG9yX2lkIjoiMzE2NjQwNDUxOTgxOTA4NjE2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 72fbfba8f4013319be98b910aa9a1445883ffe87b94b53ce75b5f8d864ebad30 |
| hovercard-subject-tag | issue:4575482672 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/150820/issue_layout |
| twitter:image | https://opengraph.githubassets.com/57af1e246b70ff1ec7242e13e599d006596f6d9841787205b352f3415c43afe8/python/cpython/issues/150820 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/57af1e246b70ff1ec7242e13e599d006596f6d9841787205b352f3415c43afe8/python/cpython/issues/150820 |
| og:image:alt | json.dumps() runs through the pure-Python iterencode() wrapper on every call, even though the C accelerator does the actual encoding. That wrapper builds a float-formatting helper closure each time... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gaborbernat |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| 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 |
| react-app-name | issues |
Links:
Viewport: width=device-width