0
0
Ruby on Railsframework~8 mins

Active Job framework in Ruby on Rails - Performance & Optimization

Choose your learning style9 modes available
Performance: Active Job framework
MEDIUM IMPACT
Active Job affects background job processing, which impacts user interaction responsiveness and server load handling.
Handling time-consuming tasks in a Rails app
Ruby on Rails
class UsersController < ApplicationController
  def create
    WelcomeEmailJob.perform_later(@user.id)
    # other code
  end
end

class WelcomeEmailJob < ApplicationJob
  queue_as :default

  def perform(user_id)
    user = User.find(user_id)
    UserMailer.welcome_email(user).deliver_now
  end
end
Offloads email sending to background job, freeing web request to respond quickly.
📈 Performance Gainreduces web request time by 200-500ms, improves INP by avoiding blocking
Handling time-consuming tasks in a Rails app
Ruby on Rails
class UsersController < ApplicationController
  def create
    UserMailer.welcome_email(@user).deliver_now
    # other code
  end
end
Sending emails synchronously blocks the web request, increasing response time and hurting user experience.
📉 Performance Costblocks rendering for 200-500ms per request depending on email server speed
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Synchronous task in requestN/AN/ABlocks response, delays paint[X] Bad
Background job with Active JobN/AN/ANon-blocking, faster response[OK] Good
Rendering Pipeline
Active Job moves heavy tasks out of the request-response cycle, so the browser rendering pipeline is less blocked by server processing delays.
Server Processing
Interaction Responsiveness
⚠️ BottleneckServer Processing during synchronous tasks
Core Web Vital Affected
INP
Active Job affects background job processing, which impacts user interaction responsiveness and server load handling.
Optimization Tips
1Offload heavy or slow tasks to background jobs to keep web requests fast.
2Avoid synchronous processing in controller actions to improve interaction responsiveness.
3Monitor background job queue length to prevent delays in task execution.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of using Active Job for heavy tasks?
AIt moves heavy tasks out of the web request to improve interaction responsiveness.
BIt reduces the size of JavaScript bundles sent to the browser.
CIt decreases the number of DOM nodes rendered on the page.
DIt improves CSS selector matching speed.
DevTools: Performance
How to check: Record a performance profile during user interaction that triggers the task; check for long server response times blocking the main thread.
What to look for: Look for long tasks or blocking time in the flame chart indicating synchronous processing delaying response.