Skip to content

Replace PyAccu with PyUnicodeWriter #95005

Closed

Description

@aivarsk

PyAccu is used only in two places:

  • JSON encoder (PyUnicodeWriter is used already for the decoder)
  • StringIO (very minimal use of PyAccu)

The newer PyUnicodeWriter seems to be a better tool for aggregating strings and removing PyAccu gets rid of >100 lines of C code while keeping the same functionality.

P.S. The new JSON encoder also performed ~10% better on a completely synthetic test encoding a 20Mb JSON. That JSON in turn was created while investigating the lack of concurrent execution in FastAPI services. Which turned out to be due to JSON encoding.

Activity

  1. mdboom commented on Jul 19, 2022

    @mdboom
    Contributor

    pyperformance has some JSON-related benchmarks. It would be good to run those in our stable benchmarking environment to confirm the performance increase before merging. I'm happy to do that if you ping me when your PR is ready for that testing.

  2. aivarsk commented on Jul 19, 2022

    @aivarsk
    ContributorAuthor

    This is pyperformance before my changes:

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

    And after my changes:

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

    There is an improvement but not as big as in my 20Mb test case.

  3. aivarsk commented on Jul 19, 2022

    @aivarsk
    ContributorAuthor

    @mdboom the PR is ready, can you run the tests?

  4. mdboom commented on Jul 19, 2022

    @mdboom
    Contributor

    The results on the standard test machine corroborate your results.

    Before your change:

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

    After your change:

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

    So, a solid improvement (and of course there are other reasons to do this besides just performance...)

  5. added a commit that references this issue on Jul 27, 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

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions