0
0
Ruby on Railsframework~8 mins

Job creation and queuing in Ruby on Rails - Performance & Optimization

Choose your learning style9 modes available
Performance: Job creation and queuing
HIGH IMPACT
This affects page load speed and user interaction responsiveness by offloading heavy tasks to background jobs.
Handling a slow task like sending emails during a web request
Ruby on Rails
def create
  UserMailer.welcome_email(@user).deliver_later
  render :show
end
Queues the email to be sent asynchronously, freeing the web request immediately.
📈 Performance GainNon-blocking request, improves INP by 200-500ms
Handling a slow task like sending emails during a web request
Ruby on Rails
def create
  UserMailer.welcome_email(@user).deliver_now
  render :show
end
Sending email synchronously blocks the web request, delaying response time.
📉 Performance CostBlocks rendering for 200-500ms depending on email server speed
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Synchronous job executionMinimalMultiple reflows due to blockingHigh paint cost due to delayed rendering[X] Bad
Asynchronous job queuingMinimalSingle reflowLow paint cost, fast rendering[OK] Good
Rendering Pipeline
Synchronous job execution blocks the main thread during the Layout and Paint stages, delaying rendering. Asynchronous queuing defers work, allowing the browser to complete rendering faster.
Layout
Paint
Composite
⚠️ BottleneckLayout and Paint stages due to blocking synchronous job execution
Core Web Vital Affected
INP
This affects page load speed and user interaction responsiveness by offloading heavy tasks to background jobs.
Optimization Tips
1Never run slow jobs synchronously during web requests.
2Use perform_later to queue jobs asynchronously.
3Monitor job queue length to avoid delays in background processing.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of queuing jobs asynchronously in Rails?
AIt prevents blocking the web request, improving input responsiveness.
BIt reduces the number of database queries.
CIt decreases the size of the JavaScript bundle.
DIt improves CSS selector matching speed.
DevTools: Performance
How to check: Record a performance profile during a web request that triggers job execution. Look for long tasks blocking the main thread.
What to look for: Long blocking tasks in the Main thread timeline indicate synchronous job execution slowing rendering.