Skip to content

Speed up ActionDispatch::Reloader for static assets 10x #23510

@mikhailov

Description

@mikhailov

Given a dummy Rails app with large number of scaffold-generated objects (Code LOC: 18849) and hundred gems (sample taken from https://github.com/discourse/discourse/blob/master/Gemfile) tried to measure performance hit for static assets. Newelic in development mode helped to figure it out thoroughly.

The problem is a middleware responsible for Ruby classes reload slows serving static assets down. Profiling with Newrelic shows the following results (88% spent on Reloader middleware):

screen shot 2016-02-06 at 01 08 48

siege benchmark results (siege -b http://localhost:3000/assets/application.js):

Transaction rate:           2.60 trans/sec
Concurrency:               11.87

I tried to skip this middleware for static assets based on condition expression (correct me if I'm wrong) env['PATH_INFO'].include?(Rails.application.config.assets.prefix) the results suprised me a bit:

screen shot 2016-02-06 at 01 09 30

siege benchmark results (siege -b http://localhost:3000/assets/application.js):

Transaction rate:          16.13 trans/sec
Concurrency:               11.82

Having some change in application.js doesn't require rails server to restart, changes reloaded on-fly as usual, the difference is no callbacks chain and no clears dependencies for static assets anymore.

This change makes a diffference in development mode when serve static assets without Nginx. Please let me know what you think, patch is available as gist for a moment: https://gist.github.com/mikhailov/7e6d925044327a87db4f

Increase LOC from 18K to 27K followed by slowness of response for non-patched middleware. It seems the complexity is O(n) compare to O(1) for code with the patch.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions