Creating HtmlParser for each HtmlSanitizer.Sanitize call? #271
DmitryZhuravkin
started this conversation in
General
Replies: 1 comment 1 reply
-
It should be ok. There is no specific motivation regarding thread safety behind the decision to use a fresh instance of I've ran a modified version of this test using a static instance of HtmlSanitizer/test/HtmlSanitizer.Tests/Tests.cs Lines 2883 to 2927 in 4a46498 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey everyone,
I used HtmlSanitizer (version 5.0.353) in multi threaded app with a big amount of strings need to be sanitized before storing into DB. I use just one instance of HtmlSanitizer across all threads. The instance configuration is pretty simple:
Usage:
public static string SanitizeAll(this string source) { var result = _plainSanitizer.Sanitize(source); return result; }
But after profiling I`ve noted that for each Sanitize call a new instance of HtmlParser is created, and this degradates performance significantly. My plan is to use just one instance of HtmlParser, something like this (performance looks pretty good for this scenario):
But I am not sure this is safe in terms of multi threading. Potentially, the approach to use one instance of HtmlParser per call is a planned decision. Could you please give me few notes about this decision? What do you think, will the approach with single instance work better in this case?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions