Skip to content

json.dumps: single circle markers hash lookup #161661

Open

Description

@aivarsk

Feature or enhancement

Right now the code does Contains + SetItem for circular reference checks. That can be done as a single hash lookup with PyDict_SetDefault and checking the dictionary size (memory read).

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. picnixz commented on Nov 9, 2026

    @picnixz
    Member

    How much perf do we gain?

  2. aivarsk commented on Nov 9, 2026

    @aivarsk
    ContributorAuthor

    Updated to PyDict_SetDefaultRef for a cleaner approach. On a synthetic case with a lot of containers it gives me ~4.5% improvement. For pyperformance it's insignificant 0.x% change.
    Now with SetDefaultRef I think it's also a cleaner code regardless of perf gains or not.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirperformancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions