riganti / dotvvm

Open source MVVM framework for Web Apps
https://www.dotvvm.com
Apache License 2.0
743 stars 97 forks source link

Improve performance of HtmlWriter and some smaller things #1851

Closed exyi closed 4 weeks ago

exyi commented 1 month ago

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