mjmlio / mjml

MJML: the only framework that makes responsive-email easy
https://mjml.io
MIT License
17.08k stars 960 forks source link

Implement a more efficient parser #394

Closed ngarnier closed 6 years ago

ngarnier commented 8 years ago

The current parser (using https://github.com/cheeriojs/cheerio) is slow and leads to some parsing issues (for special characters for example).

It would be very effective in terms of performance to create / implement a new parser more adapted to MJML.

staab commented 6 years ago

Any tips on how to get some speed improvements out of mjml in the meantime? I looked at https://github.com/mjmlio/mjml/issues/340, which referenced the speed issue for dynamic templates, but I'm skeptical an api would be any faster if the underlying library isn't tunable.

My setup is basically mjml/mustache file -> load and parse as mustache template -> render mustache template -> render mjml by using python's subprocess module and calling node_modules/mjml/bin/mjml with cli args and namedtemporaryfiles -> convert to pdf and return.

This whole process takes 8 seconds (with 500MB RAM), 50% of which is just calling mjml. Would it be faster to get rid of mustache, load the template as mjml and implement my own template manipulation logic so I can pass mjml as json rather than xml to the binary? Would it be faster to call mjml directly from node (I have a microservice that handles pdf-rendering related tasks written in node, so this would be pretty convenient for me)?

ngarnier commented 6 years ago

Hey @staab, sorry for the late reply, 'tis the season!

Sounds like a lot is happening here, it would be useful to isolate/remove steps to pin down the latency due to each step.

Indeed, the faster you can get regarding the MJML to HTML conversion is:

If you can try that and get back to us it would be super interesting, you'll improve for sure the performance (especially with the second step).

You might also be interested in trying the MJML 4 beta (you can install with npm install mjml@next and use https://github.com/ngarnier/mjml-migrate to migrate your v3 templates).

ngarnier commented 6 years ago

The first beta release for MJML 4 is here so I'm closing! npm install mjml@next