Module: ActionController::Routing::Optimisation

Included in:
RouteSet::NamedRouteCollection
Defined in:
lib/action_controller/routing/optimisations.rb

Overview

Much of the slow performance from routes comes from the complexity of expiry, :requirements matching, defaults providing and figuring out which url pattern to use. With named routes we can avoid the expense of finding the right route. So if they've provided the right number of arguments, and have no :requirements, we can just build up a string and return it.

To support building optimisations for other common cases, the generation code is separated into several classes

Defined Under Namespace

Classes: Optimiser, PositionalArguments, PositionalArgumentsWithAdditionalParams

Constant Summary collapse

OPTIMISERS =
[PositionalArguments, PositionalArgumentsWithAdditionalParams]

Instance Method Summary collapse

Instance Method Details

#generate_optimisation_block(route, kind) ⇒ Object


13
14
15
16
17
18
19
# File 'lib/action_controller/routing/optimisations.rb', line 13

def generate_optimisation_block(route, kind)
  return "" unless route.optimise?
  OPTIMISERS.inject("") do |memo, klazz|
    memo << klazz.new(route, kind).source_code
    memo
  end
end