-
Notifications
You must be signed in to change notification settings - Fork 426
feature: use pool for EscapeHTML #866
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
feature: use pool for EscapeHTML #866
Conversation
|
DON'T change the format otherwise it is hard to review. |
|
Reverted gofmt. For the design, the issue of #835 was caused by:
To make the change to reduce this allocation:
For the benchmark, check out the following benchmark code based on the payload in the linked issue: func BenchmarkSonicEscapeHTML(b *testing.B) {
payload := new(infobipResponse)
err := json.Unmarshal([]byte(data), payload)
require.NoError(b, err)
api := sonic.Config{EscapeHTML: true}.Froze()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = api.Marshal(payload)
}
}Here is the result from the old code (48ba40b): Here is the result from the new code (fedc295): See the decrease in allocation count and allocated bytes per operation. |
|
how about the performace of JSON without HTLM chars? Including both CPU and MEM |
The previous result payload does not contain any HTML chars. From my understanding, currently the EscapeHTML logic will be executed with the allocation, regardless whether the payload contain any HTML chars or not. Here is another result I got when running the experiment using sensitive payload:
|
What type of PR is this?
Use sync.Pool to get buffer for EscapeHTML and utf8.Validate to decrease allocation. Related to #835 .
Check the PR title.
Which issue(s) this PR fixes:
#835