html-minifier icon indicating copy to clipboard operation
html-minifier copied to clipboard

Insanely slow on large files

Open Nuru opened this issue 4 years ago • 1 comments

I tried html-minifier but it was insanely slow on one of the first test files I fed it. I looked at #546 but that slowdown was on invalid input and supposedly fixed. As far as I can tell, the input file was well formed, but quite large: 3,450,556 bytes. Still, much smaller than ES6 table listed in the README as being successfully minimized.

Just reading in the file and doing the default (which is basically nothing) took 3.5 minutes (220 seconds):

$ time html-minifier -o x.html index.html

real	3m30.062s
user	3m29.046s
sys	0m0.537s

Running html-minifier with real minification options took, well, I don't know, I gave up after 25 hours (90,000 seconds) and stopped it.

$ time html-minifier --collapse-whitespace --conservative-collapse --collapse-inline-tag-whitespace --case-sensitive \
  --continue-on-parse-error --preserve-line-breaks --prevent-attributes-escaping --remove-optional-tags \
  --keep-closing-slash  --remove-tag-whitespace -o x.html index.html

workaround

Giving up on html-minifier in favor of minify which minified the same page in well under 0.1 seconds:

$ time minify --html-keep-end-tags --html-keep-document-tags --html-keep-whitespace -v -o x.html index.html 
infer mimetype from file extensions
minify to output file x.html
(61.852901ms, 3.5 MB, 223 kB,   6.4%,  56 MB/s) - index.html to x.html
finished in 65.434042ms

real	0m0.072s
user	0m0.028s
sys	0m0.053s

Nuru avatar Feb 12 '22 09:02 Nuru

@Nuru, does this still persist? If yes, would pick this up for analysis in HTML Minifier Next (maintained fork).

j9t avatar Sep 20 '25 11:09 j9t