GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-161661: json.dumps use a single dict probe for circular-reference markers by aivarsk · Pull Request #161662 · python/cpython

Conversation

@aivarsk

@aivarsk aivarsk commented Nov 9, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

One less hash calculation and lookup per circular reference check.

  • Issue: json.dumps: single circle markers hash lookup #161661

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting review type-feature A feature request or enhancement labels Nov 9, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Nov 9, 2026
json.dumps: single circle markers hash lookup #161661
Open
@aivarsk
json: use a single dict probe for circular-reference markers
7fa0231
@aivarsk
aivarsk force-pushed the json-dumps-markers-setdefault branch from 0e056ec to 7fa0231 Compare November 9, 2026 09:24
@picnixz

picnixz commented Nov 9, 2026

Copy link
Copy Markdown
Member

This adds a Py_DECREF path which may, on free-threading, introduce refcounting contention. Can you check the impact as well please?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aivarsk

aivarsk commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

The synthetic test with a lot of containers there is improvement for free-threading as well but a bit smaller.
GIL: base → branch: 33.73 → 32.05 ms (-5.0%)
FT: base → branch : 40.59 → 39.08 ms (-3.7%)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Nov 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

What about pyperformance's JSON benchmark? And how is the synthetic benchmark done? (PGO+LTO? release build? pyperf or time? if it's timeit, use pyperf instead)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aivarsk

aivarsk commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

The built was just a plain -O3, no PGO+LTO. The existing pyperformance cases did show 0.x improvement but that's insignificant. Could be noise in eiter direction, as this is my laptop.
My synthetic testcase did use pyperf, just with a lot of nested containers to pressure the circular checks
jsondumps.py

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz

picnixz commented Nov 9, 2026

Copy link
Copy Markdown
Member

FTR, please don't add attachments. Users usually don't want to download code so prefer using inline blocks (in a <details> section).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Nov 9, 2026
View reviewed changes

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change could be done but at the same time, I'd prefer not touching code that has been settled for a while especially considering the lack of significant performance in either direction.

So I'll defer the final decision to @serhiy-storchaka

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nineteendo

nineteendo commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

How does this compare to using a set?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aivarsk

aivarsk commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@nineteendo haven't tried it because markers is a dict and here it's a minimal change without API changes I came up with during #137103. If API change is on the table I think limiting recursion depth like other libraries do is the best way.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nineteendo

nineteendo commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

I think you can also check the size before and after adding the element.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@picnixz picnixz picnixz left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@aivarsk @picnixz @nineteendo
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.