Skip to content

Replace builtin json with faster ujson package. #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2024

Conversation

purple4reina
Copy link
Contributor

@purple4reina purple4reina commented Apr 10, 2024

What does this PR do?

Replaces instances of the builtin json package to use ujson instead.

Motivation

The builtin json package is pretty slow for loading/dumping data. There are faster alternatives.

Testing Guidelines

Additional Notes

I evaluated several packages to determine which was best.

package total mean bench* package size
json 22269.8497 -
ujson 20729.369 184K
msgspec 22589.6351 604K
orjson 21399.4234 628K
rapidjson 20626.785 916K
simplejson 22365.0746 288K

* "total mean bench" is the sum of all the mean durations of all benchmarks.

Some packages were faster/slower depending on the lambda event payload. But I ultimately went with ujson because it is generally one of the fastest, plus has smallest package size.

Some benchmark results

Comparison of json and ujson when extracting trace context from an sqs batch event.

benchmark_20240410_182330-test_tracing_extract_dd_trace_context sqs-batch

Curling lambda url with capture lambda payload true.

Screenshot 2024-04-10 at 2 57 41 PM

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog
  • This PR passes the integration tests (ask a Datadog member to run the tests)

@purple4reina purple4reina marked this pull request as ready for review April 10, 2024 21:58
@purple4reina purple4reina requested a review from a team as a code owner April 10, 2024 21:58
Copy link
Contributor

@astuyve astuyve left a comment

Choose a reason for hiding this comment

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

Needs to be added to the LICENSE-3rdparty.csv file, otherwise it's good

@purple4reina purple4reina merged commit f9aca11 into main Apr 11, 2024
51 checks passed
@purple4reina purple4reina deleted the rey.abolofia/json-dumps branch April 11, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants