Giter Site home page Giter Site logo

Speed up minification about minify HOT 4 CLOSED

tdewolff avatar tdewolff commented on May 13, 2024
Speed up minification

from minify.

Comments (4)

tdewolff avatar tdewolff commented on May 13, 2024

17f97c5 has been pushed with 10% speed improvement.

These changes need to occur to make it faster, and I'm not sure if it's worth it:

  • the HTML tokenizer returns strings, would save a realloc to return []byte
  • the CSS parser builds a node tree which is heavy on allocs and the GC
  • ignore io.Writer errors from Write (not sure if this is safe)
  • the HTML minifier functions takes most time, but there isn't a way to improve it much...

from minify.

tdewolff avatar tdewolff commented on May 13, 2024

e346a3c pushed with another 10% speed improvement.

It now takes []byte instead of string from the HTML tokenizer and uses atom.Atom enum for tags and attributes for fast comparison (instead of []byte equality tests).

Ignoring io.Writer errors will not increase performance significantly.

The only way to speed up is to reduce memory usage, but that is hardly possible!

from minify.

tdewolff avatar tdewolff commented on May 13, 2024

Great improvement of 30% with e219023 and somewhat with 31ef4d6 by refactoring the code.

Speed could be improved if HTML tokenizer didn't unescape text tokens and attribute values, so the minifier wouldn't have to re-escape them.

from minify.

tdewolff avatar tdewolff commented on May 13, 2024

HTML minification speed significantly increased by writing a new tokenizer 3b90fc7. The tokenizer is equal in speed, but more assumptions can be made to avoid memory copying and HTML entities re-escaping. Most of the speed improvement is actually from re-using the token buffer better and other things.

Avoiding allocations in 9831f46 also helped.

Additonally, the bytes.Equal is slightly slower for some reason than self-implementing it. And by using literal byte slices instead of literal strings to byte slice casts improved speed too: b36014e.

Furthermore, attribute escaping was a bottleneck: df03a65

Total speed increased by almost 50%!

from minify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.