-
Notifications
You must be signed in to change notification settings - Fork 68
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
[WIP] Add ujson as alternative JSON encoder #130
base: dev
Are you sure you want to change the base?
Conversation
Any specific reason to choose |
Supporting ujson supports custom type serialisation via a |
Codecov Report
@@ Coverage Diff @@
## dev #130 +/- ##
==========================================
- Coverage 86.04% 85.79% -0.26%
==========================================
Files 50 51 +1
Lines 2903 2922 +19
Branches 391 396 +5
==========================================
+ Hits 2498 2507 +9
- Misses 329 336 +7
- Partials 76 79 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Another variation Move expression remove braces Change to underscore
I've deployed 2 Azure Functions in Australiaeast with this patch applied and without the patch applied The sample POST request is: {
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
} The function source code is: import azure.functions as func
import json
def main(req: func.HttpRequest) -> func.HttpResponse:
try:
req_body = req.get_json()
except ValueError:
pass
return func.HttpResponse(
json.dumps(req_body),
status_code=200
) The script to test the two deployments: $ ab -p test_data.json -T application/json -n 1000 -c 10 https://ant-functions-load-testing.azurewebsites.net/api/httptriggertest
$ ab -p test_data.json -T application/json -n 1000 -c 10 https://ant-functions-load-testing-og.azurewebsites.net/api/httptriggertest The results are:
I've subtracted 70ms as this was the mean connect time, so you can more clearly see the difference between the two branches. 10% faster in the 50th percentile, but importantly 2.3x faster in the 95th percentile. |
The standard library
json
module is the slowest of the json encoders.ujson is 10-20x faster at encoding and decoding, especially for large datasets.
This PR moves the
json
imports into a shim module, which picks the standard library implementation or ujson depending on whether: