Skip to content
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

Improve performance of HtmlWriter and some smaller things #1851

Merged
merged 5 commits into from
Sep 7, 2024

Conversation

exyi
Copy link
Member

@exyi exyi commented Aug 28, 2024

The main optimization is to use String.IndexOf for finding HTML-dangerous characters while doing encoding. Since IndexOf is vectorized, it can be up to an order of magnitude faster than our previous implementation, especially when no characters need escaping.

The LongHtmlString benchmark with many escaped characters goes from 34-40ms to 29-34ms. The LongJsonString with no escaped characters goes from 17-26ms to 1.5-2.5ms.

The full-stack performance sample goes from ~798ms to ~641ms on .NET 8 without PGO. The difference on other platforms is also in the ~ 5-10% range

The benchmark results are in these attachment: main.csv perf-htmlwriter-indexof.csv

@exyi exyi added this to the Version 4.3 milestone Sep 7, 2024
@tomasherceg tomasherceg merged commit c0a911e into main-v4 Sep 7, 2024
14 of 15 checks passed
@tomasherceg tomasherceg deleted the perf-htmlwriter-indexof branch September 7, 2024 15:04
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