Taritsyn / WebMarkupMin

The Web Markup Minifier (abbreviated WebMarkupMin) - a .NET library that contains a set of markup minifiers. The objective of this project is to improve the performance of web applications by reducing the size of HTML, XHTML and XML code.
Apache License 2.0
449 stars 48 forks source link

Can't minify multiple documents in parallel? #133

Closed edumbell closed 2 years ago

edumbell commented 2 years ago

Hi, I am using an instance of WebMarkupMin.Core.HtmlMinifier 2.9 to minify a large number of emails but it is too slow. I see CPUs are barely being used, so tried to run the minification in e.g. a Parallel.For, but nothing I do improves performance or uses more CPUs. Do you have a static lock around the main work? Do you need that? I could understand if each instance has some contested resource, but it would be nice if we could construct an instance per thread and not have them interfere with each other.

I have also tried setting all "Minify..." and "Remove..." settings to false but it doesn't seem to improve performance at all. Any other suggestions much appreciated!

Taritsyn commented 2 years ago

Hello!

Do you have a static lock around the main work?

Locks are used only at the instance level.

Any other suggestions much appreciated!

  1. Try running the minifier under .NET 5.
  2. Try implementing a pool of HtmlMinifier instances (you can use the Microsoft.Extensions.ObjectPool library as a basis).