Performance: Mailer generation and templates
MEDIUM IMPACT
This affects the server response time and initial email generation speed, impacting how fast emails are prepared and sent.
class UserMailer < ApplicationMailer def welcome_email(user) @user = user mail(to: @user.email, subject: 'Welcome!') end end # In app/views/user_mailer/welcome_email.html.erb <h1>Welcome, <%= @user.name %>!</h1> # In app/views/user_mailer/welcome_email.text.erb Welcome, <%= @user.name %>!
class UserMailer < ApplicationMailer def welcome_email(user) @user = user mail(to: @user.email, subject: 'Welcome!') do |format| format.html { render inline: "<h1>Welcome, <%= @user.name %>!</h1>" } format.text { render plain: "Welcome, #{@user.name}!" } end end end
| Pattern | Template Parsing | CPU Load | I/O Blocking | Verdict |
|---|---|---|---|---|
| Inline ERB in mailer method | High (per email) | High | Low | [X] Bad |
| Precompiled ERB templates | Low (once) | Low | Low | [OK] Good |
| Synchronous large file read | Low | Medium | High | [X] Bad |
| Background job for attachments | Low | Low | Low | [OK] Good |