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 — Fastpath for encoding unsorted dict to JSON · Issue #95385 · python/cpython

Fastpath for encoding unsorted dict to JSON #95385

New issue
Copy link
New issue
Copy link
Closed
Closed
Fastpath for encoding unsorted dict to JSON#95385
Copy link
Labels
3.12only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

Description

@aivarsk
aivarsk
opened on Jul 28, 2022
Issue body actions

JSON encoder can produce output sorted by key (json.dumps(sort_keys=True)) The default value for sort_keys is False. The code always creates a list of dictionary items, sorts them if needed, and then iterates through them.
However, if sorting is not requested we can use PyDict_Next to avoid allocating a list of tuples.

pyperformance on my machine before changes:

### json_dumps ###
Mean +- std dev: 10.6 ms +- 0.1 ms

pyperformance after changes:

### json_dumps ###
Mean +- std dev: 9.00 ms +- 0.08 ms

Activity

  1. aivarsk
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jul 28, 2022
  2. mdboom
    added
    performancePerformance or resource usagePerformance or resource usage
    on Jul 28, 2022
  3. aivarsk commented on Jul 29, 2022

    @aivarsk
    aivarsk
    on Jul 29, 2022
    ContributorAuthor
    More actions

    Patched pyperformance to use json.dumps(sort_keys=True)

    before changes

    ### json_dumps ###
    Mean +- std dev: 14.0 ms +- 0.2 ms
    

    after changes

    ### json_dumps ###
    Mean +- std dev: 13.6 ms +- 0.2 ms
    

    Probably because the new code does not create an iterator from the list and PyList_GET_ITEM is a bit faster than PyIter_Next (extra incref/decref)?

  4. corona10
    closed this as completedon Aug 6, 2022
  5. corona10
    added a commit that references this issue on Aug 6, 2022

    gh-95385 Fastpath for encoding dict to JSON (gh-95374)

    15f4a35
  6. iritkatriel
    added a commit that references this issue on Aug 11, 2022

    pythongh-95385 Fastpath for encoding dict to JSON (pythongh-95374)

    2d2e23a
  7. serhiy-storchaka
    added this to JSON issueson Dec 15, 2022
  8. serhiy-storchaka
    added
    3.12only security fixesonly security fixes
    on Dec 15, 2022
  9. serhiy-storchaka commented on Dec 15, 2022

    @serhiy-storchaka
    serhiy-storchaka
    on Dec 15, 2022
    Member
    More actions

    It caused a regression for OrderedDict. See #100272.

  10. serhiy-storchaka
    moved this to Done in JSON issueson Dec 17, 2022
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

    3.12only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

    Projects

    • JSON issues
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.