sighmon / mjml-rails

MJML + ERb/Haml/Slim view template
https://mjml.io
Other
295 stars 64 forks source link

Slow to render layout, and too much object(memory) Allocations #105

Open Kohei909Otsuka opened 1 year ago

Kohei909Otsuka commented 1 year ago

Using gem "mjml-rails", "~> 4.8.0" it takes too long time to render layout, 20 seconds when worst.

Can you help me?

I have no idea why it takes so long time.

log

2023-03-22T07:00:23.1429795Z    pre-sidekiq I, [2023-03-21T22:00:20.461420 #161]  INFO -- : [ActiveJob] Enqueued ActionMailer::MailDeliveryJob (Job ID: 3a2596bc-c818-442f-935a-742979d4cff1) to Sidekiq(default) with arguments: "SupplierMailers::SupplierMailer", "quotation_answer_reminder_to_supplier_email", "deliver_now", {:params=>{:quotation_request_member=>#<GlobalID:0x00007fd1791eb520 @uri=#<URI::GID gid://tenant-backend/QuotationRequestMember/29>>}, :args=>[]}    PrimaryResult
2023-03-22T07:02:12.1794285Z    pre-sidekiq I, [2023-03-21T22:02:11.558580 #161]  INFO -- : [ActiveJob] [ActionMailer::MailDeliveryJob] [3a2596bc-c818-442f-935a-742979d4cff1]   Rendered supplier_mailers/supplier_mailer/quotation_answer_reminder_to_supplier_email.html.mjml within layouts/supplier_mailer (Duration: 179.7ms | Allocations: 9239) PrimaryResult
2023-03-22T07:02:12.1794285Z    pre-sidekiq I, [2023-03-21T22:02:10.965977 #161]  INFO -- : [ActiveJob] [ActionMailer::MailDeliveryJob] [3a2596bc-c818-442f-935a-742979d4cff1] Performing ActionMailer::MailDeliveryJob (Job ID: 3a2596bc-c818-442f-935a-742979d4cff1) from Sidekiq(default) enqueued at 2023-03-21T22:00:20Z with arguments: "SupplierMailers::SupplierMailer", "quotation_answer_reminder_to_supplier_email", "deliver_now", {:params=>{:quotation_request_member=>#<GlobalID:0x00007f92df570d40 @uri=#<URI::GID gid://tenant-backend/QuotationRequestMember/29>>}, :args=>[]}    PrimaryResult
2023-03-22T07:02:33.1309723Z    pre-sidekiq I, [2023-03-21T22:02:31.861821 #161]  INFO -- : [ActiveJob] [ActionMailer::MailDeliveryJob] [3a2596bc-c818-442f-935a-742979d4cff1]   Rendered layout layouts/supplier_mailer.text.erb (Duration: 1.9ms | Allocations: 377)  PrimaryResult
2023-03-22T07:02:33.1309723Z    pre-sidekiq I, [2023-03-21T22:02:31.859163 #161]  INFO -- : [ActiveJob] [ActionMailer::MailDeliveryJob] [3a2596bc-c818-442f-935a-742979d4cff1]   Rendered layout layouts/supplier_mailer.html.mjml (Duration: 20480.5ms | Allocations: 76291)   PrimaryResult
2023-03-22T07:02:33.1309723Z    pre-sidekiq I, [2023-03-21T22:02:31.861299 #161]  INFO -- : [ActiveJob] [ActionMailer::MailDeliveryJob] [3a2596bc-c818-442f-935a-742979d4cff1]   Rendered supplier_mailers/supplier_mailer/quotation_answer_reminder_to_supplier_email.text.erb within layouts/supplier_mailer (Duration: 1.3ms | Allocations: 241) PrimaryResult
2023-03-22T07:02:34.4510409Z    pre-sidekiq I, [2023-03-21T22:02:33.662105 #161]  INFO -- : [ActiveJob] [ActionMailer::MailDeliveryJob] [3a2596bc-c818-442f-935a-742979d4cff1] Performed ActionMailer::MailDeliveryJob (Job ID: 3a2596bc-c818-442f-935a-742979d4cff1) from Sidekiq(default) in 22992.59ms   PrimaryResult
2023-03-22T07:02:34.4510409Z    pre-sidekiq I, [2023-03-21T22:02:33.661777 #161]  INFO -- : [ActiveJob] [ActionMailer::MailDeliveryJob] [3a2596bc-c818-442f-935a-742979d4cff1] Delivered mail 641a2977eafad_a1141406962e@pre-sidekiq--26r31ts-858bf784f9-8x2rx.mail (1700.7ms)  PrimaryResult

point is ...

Rendered layout layouts/supplier_mailer.text.erb (Duration: 1.9ms | Allocations: 377)  PrimaryResult
Rendered layout layouts/supplier_mailer.html.mjml (Duration: 20480.5ms | Allocations: 76291) PrimaryResult
====> 20seconds to render layout!!

content of layouts/supplier_mailer.html.mjml

<mjml>
  <mj-head>
    <mj-attributes>
      <mj-button background-color="#1976d2" color="white" />
      <mj-divider border-width="1px" border-style="solid" border-color="#cccccc" />
      <mj-all font-family="Hiragino Sans, sans-serif" font-size="15px" />
    </mj-attributes>
    <mj-style>
      .receiver {
        font-size: 18px !important;
        font-weight: bold;
      }

      .important {
        color: #1976d2 !important;
        font-weight: bold;
      }

      .alert {
        color: #d21919 !important;
        font-weight: bold;
      }

      .from {
        font-size: 13px;
        background-color: #ddd;
        padding:3px;
        border-radius:15%
      }

      p {
        line-height: 0.7;
      }
    </mj-style>
  </mj-head>
  <mj-body background-color="#f0f0f0">
    <mj-section padding-top="30px" padding-bottom="0px">
      <mj-column>
        <mj-text align="center" color="#085995" font-family="Roboto">
          <h1>Nitoel</h1>
        </mj-text>
      </mj-column>
    </mj-section>

    <mj-section background-color="#fff">
      <%= yield %>
    </mj-section>

    <mj-section>
      <mj-column>
        <mj-text font-size="12px" align="center">
          本メールは送信専用メールアドレスから送信されております。<br />
          ご返信いただいてもお答えできませんのでご了承ください。<br />
          ご不明点がございましたら、依頼元担当者様宛にお問い合わせをお願いいたします。
        </mj-text>
      </mj-column>
    </mj-section>
  </mj-body>
</mjml>
sighmon commented 1 year ago

@Kohei909Otsuka How are you installing it? Have you tried anything in this thread: https://github.com/sighmon/mjml-rails/issues/76#issuecomment-1238011317