Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve MJML Mailer Performance by Caching Compiled Templates #126

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bugloper
Copy link

@bugloper bugloper commented Oct 1, 2024

Problem
Currently, MJML templates are compiled every time a mailer is called, which significantly slows down test execution. This can impact overall performance, especially in test suites with frequent mailer calls.

Proposed Solution
This PR introduces caching for compiled MJML templates, leveraging the fact that mailer templates typically do not change frequently. Compiled templates are now cached in tmp/mjml_cache, and if a template is modified, it automatically detects the change, recompiles the template, and updates the cache.

How it Works:

  1. When a mailer is called, if a cache does not exist, the system calculates a unique fingerprint (using SHA256) based on the content of the template file.
  2. The next time the mailer is called with the same template, it retrieves the cached version, resulting in a significant performance boost.

Caveats:

Dynamic data/local variables: The dynamic data passed from your tests will not be reflected in the cached templates. To avoid this, consider:

  1. Using static data in your tests instead of tools like Faker.
  2. Writing smarter specs by using regex patterns to check for the presence of values rather than validating exact matches.

If you have suggestions for improving these caveats or avoiding them entirely, I'd love to hear your feedback!

@bugloper
Copy link
Author

bugloper commented Oct 1, 2024

@sighmon I will fix those failed checks and still have some more to do. Just want to know this is a good idea. It speeds test by a lot(there are some caveats).

@bugloper bugloper changed the title add cache to precompile mjml files in test env Improve MJML Mailer Performance by Caching Compiled Templates Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant