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

Classes and Modules
Class ActionController::Routing::Optimisation::Optimiser
Class ActionController::Routing::Optimisation::PositionalArguments
Class ActionController::Routing::Optimisation::PositionalArgumentsWithAdditionalParams
OPTIMISERS = [PositionalArguments, PositionalArgumentsWithAdditionalParams]
Public Instance methods
generate_optimisation_block(route, kind)
    # File actionpack/lib/action_controller/routing/optimisations.rb, line 13
13:       def generate_optimisation_block(route, kind)
14:         return "" unless route.optimise?
15:         OPTIMISERS.inject("") do |memo, klazz|
16:           memo <<, kind).source_code
17:           memo
18:         end
19:       end