-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Make |tojson
and few more filters faster
#1008
Conversation
Also, I think the default |
|tojson
filter faster |tojson
and few more filters faster
What are the costs of making JSON pretty? I'm inclined to think the cost of JSON encoding will probably not show up for people and in most contexts pretty JSON will be helpful more than it will be harmful (because of increased size). So there's a trade-off:
I would argue that (3) is likely to outstrip (1) and (2), but obviously it depends on the situation. (To be clear, I'm arguing that you might want to look at your HTML/JS source code sometimes and when you do, it will be nice if you can follow the general structure of the JSON code, even if the JSON is not shown to the actual user.) |
Let's keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff! Have a bunch of suggestions but nothing major.
This PR changes the filter `|tojson` so that it does not collect the serialized data into a string, but writes the data into the target writer directly. This makes the benchmark run 81% (only serializing) or 39% (serializing and escaping for HTML) faster. The benchmarked data is not a fair representation for the data you would most likely serialize, though.
So, I let all filters return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, great work!
This
proof-of-conceptPR changes the filter|tojson
so that it does not collect the serialized data into a string, but writes the data into the target writer directly.This makes the benchmark run 81% (only serializing) or 39% (serializing and escaping for HTML) faster. The benchmarked data is not a fair representation for the data you would most likely escape, though.