-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Caching for canonicalised JSON #62
Caching for canonicalised JSON #62
Conversation
f7feab9
to
6b3f0b0
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Here is the performance impact on the "recursive" branch. Config:
Schema 1. One of the simplest recursive schemas: SCHEMA = {
"properties": {"foo": {"$ref": "#"}},
"additionalProperties": False,
"type": "object",
}
Here, the impact is almost not visible. But there are no negative observations at least. Schema 2. A tree-like structure with an array of child nodes: {
"definitions": {
"Node": {
"type": "object",
"properties": {
"children": {
"type": "array",
"items": {"$ref": "#/definitions/Node"},
"maxItems": 2,
}
},
"required": ["children"],
"additionalProperties": False,
},
},
"$ref": "#/definitions/Node",
}
Here it is much more visible with the average almost 2x improvement. Schema 3. A subset of Open API schema (which now works locally - I push changes to that branch soon): SCHEMA = {
"type": "object",
"required": ["paths"],
"properties": {"paths": {"$ref": "#/definitions/Paths"}},
"additionalProperties": False,
"definitions": {
"Schema": {
"type": "object",
"properties": {"items": {"$ref": "#/definitions/Schema"}},
"additionalProperties": False,
},
"MediaType": {
"type": "object",
"properties": {"schema": {"$ref": "#/definitions/Schema"}},
"patternProperties": {"^x-": {}},
"additionalProperties": False,
},
"Paths": {
"type": "object",
"patternProperties": {
"^\\/": {"$ref": "#/definitions/PathItem"},
"^x-": {},
},
"additionalProperties": False,
},
"PathItem": {
"type": "object",
"properties": {
"parameters": {
"type": "array",
"items": {"$ref": "#/definitions/Parameter"},
"uniqueItems": True,
},
},
"patternProperties": {
"^(get|put|post|delete|options|head|patch|trace)$": {
"$ref": "#/definitions/Operation"
},
"^x-": {},
},
"additionalProperties": False,
},
"Operation": {
"type": "object",
"required": ["responses"],
"properties": {
"parameters": {
"type": "array",
"items": {"$ref": "#/definitions/Parameter"},
"uniqueItems": True,
},
},
"additionalProperties": False,
},
"Parameter": {
"type": "object",
"properties": {
"schema": {"$ref": "#/definitions/Schema"},
"content": {"type": "object", "minProperties": 1, "maxProperties": 1},
},
"additionalProperties": False,
},
},
}
Slightly weaker improvement, but still visible. I don't know how this change will affect more complex schemas once the support for them will be implemented, but I suspect somehow moderate improvement from almost nothing to ~50%. Will try to make more experiments |
This comment has been minimized.
This comment has been minimized.
6b3f0b0
to
b40f420
Compare
And I will add some more measurement for non-recursive schemas, but at first glance, this change gives some minor improvements there as well. |
I tried the following non-recursive schema:
It includes a lot of different keywords, so I see it like some average schema. The results are: No cache: 447.7 ms ± 1.3 ms To me, the results seem near the error threshold. The cache statistic - For Schema 2 from my previous message, the statistic is:
and increasing the cache size up to 1024 gives a bit more improvements - up to -49.5% with the following cache statistic:
So, I am wondering if this change brings enough. For recursive schemas, it seems to give nice improvements, but I am not sure about the corner cases where it can make the performance worse. I probably could keep this PR open until the point when the recursive schemas support is ready, and then there will be more evidence to check - maybe there is something else that slows down the CI jobs that much. What do you think? |
Let's keep it open for now. To be clear, I intend to merge this pretty much as-is unless we learn something surprisingly dramatic later on - a 50% speedup is a big deal! However, I also want to take some time next week to play around with it for myself and maybe split out the serialisation logic to a separate module for clarity. Thanks again! |
b40f420
to
1f2c697
Compare
1f2c697
to
46de172
Compare
Just checking in - I've been pretty busy lately with PyCon Australia and HypoFuzz, but wanted to let you know that haven't forgotten this and it's up near the top of my open source todo list 🙂 |
Cool! :) Thank you for these links and for checking in; much appreciated :) |
Ref: #61 (comment)
A prettified version of that draft with your suggestion applied. I will evaluate its impact on the recursive schemas branch and will post it here.