Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run the compilation at startup rather than first request #1902

Closed
viraptor opened this issue Aug 29, 2019 · 11 comments
Closed

How to run the compilation at startup rather than first request #1902

viraptor opened this issue Aug 29, 2019 · 11 comments
Labels

Comments

@viraptor
Copy link

I'm having an issue where the first request (or a number of first requests - one per worker) takes much longer than the rest. That extra time is spent running Grape::API.compile.

I'd like to find a way to run that process during application startup instead (I'm running grape directly from rack). Doing it before I fork workers would also help a lot.

I've done some obvious attempts without success. Is there some snippet showing how to achieve manual initialisation?

@dblock
Copy link
Member

dblock commented Aug 29, 2019

If you hold an API instance you can call Grape::API::Instance#compile. Is the issue finding the root of your API? What have you tried?

I tried adding this to grape-on-rack api.rb and it worked.

puts Acme::API.instance # => nil
Acme::API.compile
puts Acme::API.instance  # => #<#<Class:0x00007f9bc56ae448>:0x00007f9bc4954658>

I'd like a PR to this effect in the documentation once you've figured this out? Thanks.

@myxoh
Copy link
Member

myxoh commented Sep 3, 2019

I've generated a very small test, but it seems just compiling doesn't actually reduce the time of the first call.
This is my test:

require 'benchmark'
puts Benchmark.measure {
  puts `curl localhost:9292/ping`
}

And the results with or without compiling on rackup are 0.015 for the first call, and ~0.0075 for all subsequent calls

this is my config.ru

require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
require './small_api.rb'

SmallAPI.compile
run SmallAPI

I've also attempted

require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
require './small_api.rb'
warmup do |app|
  app.compile
end

run SmallAPI

@myxoh
Copy link
Member

myxoh commented Sep 3, 2019

Note that warming up using Rack mock to actually call the API does the trick:

require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
require './small_api.rb'
warmup do |app|
  client = Rack::MockRequest.new(app)
  client.get('/ping')
end

run SmallAPI

That's a workable work around but I'm not too thrilled about it

@dblock
Copy link
Member

dblock commented Sep 3, 2019

I'm looking forward to someone attaching a profiler to this! :)

@myxoh
Copy link
Member

myxoh commented Sep 3, 2019

After attaching a profiler I've figured the difference is that, even when pre-compiling, we seem to be requiring many files and / or libraries (possibly because of the autoloader?) on the first API call

The profiler was attached to the Grape::API::Instance#call!

          require 'ruby-prof'
          # profile the code
          RubyProf.start
          response = instance.call(env)
          result = RubyProf.stop
          printer = RubyProf::FlatPrinter.new(result)
          printer.print(STDOUT)
          response

Here are both calls
1st call

Measure Mode: wall_time
Thread ID: 47125432055220
Fiber ID: 47125431251740
Total: 0.015165
Sort by: self_time

 %self      total      self      wait     child     calls  name
 43.67      0.011     0.007     0.001     0.004       28  *Kernel#require
  3.65      0.001     0.001     0.000     0.000       24   Module#class_eval
  1.17      0.002     0.000     0.000     0.002      115  *Array#each
  1.01      0.001     0.000     0.000     0.001      122  *Class#new
  0.96      0.000     0.000     0.000     0.000       34   IO#set_encoding
  0.86      0.000     0.000     0.000     0.000      296   Kernel#class
  0.81      0.001     0.000     0.000     0.001       86   Enumerable#inject
  0.62      0.001     0.000     0.000     0.001       74   Mustermann::AST::Translator#decorator_for
  0.55      0.000     0.000     0.000     0.000       66   Hash#initialize_copy
  0.52      0.000     0.000     0.000     0.000      191   Module#name
  0.49      0.000     0.000     0.000     0.000       69  *Kernel#initialize_dup
  0.46      0.000     0.000     0.000     0.000      257   Module#method_added
  0.44      0.000     0.000     0.000     0.000      188   Kernel#is_a?
  0.42      0.000     0.000     0.000     0.000      191   <Class::Mustermann::AST::Translator>#dispatch_table
  0.39      0.000     0.000     0.000     0.000       74   Mustermann::AST::Translator::NodeTranslator#initialize
  0.37      0.000     0.000     0.000     0.000      122   Array#concat
  0.35      0.000     0.000     0.000     0.000       28   Grape::DSL::Settings#get_or_set
  0.34      0.000     0.000     0.000     0.000        9   Hash#each_pair
  0.34      0.000     0.000     0.000     0.000       57   Hash#merge
  0.33      0.000     0.000     0.000     0.000       74   Module#ancestors
  0.32      0.000     0.000     0.000     0.000        2   Regexp#match
  0.31      0.000     0.000     0.000     0.000        5   Module#attr_accessor
  0.30      0.000     0.000     0.000     0.000       74   #<Class:0x0055b87dd96968>#__setobj__
  0.28      0.000     0.000     0.000     0.000       55   Kernel#respond_to?
  0.26      0.000     0.000     0.000     0.000       74   Delegator#initialize
  0.26      0.004     0.000     0.000     0.004        9  *<Module::ActiveSupport::Notifications>#instrument
  0.26      0.006     0.000     0.000     0.006        1   Grape::Endpoint#build_stack
  0.26      0.000     0.000     0.000     0.000      106   Array#any?
  0.23      0.000     0.000     0.000     0.000       28   Symbol#to_s
  0.22      0.000     0.000     0.000     0.000       56   #<Class:0x0055b87dd96968>#__getobj__
  0.22      0.000     0.000     0.000     0.000       44   #<Class:0x0055b87dd96968>#payload
  0.20      0.000     0.000     0.000     0.000        1   Grape::Cookies#read
  0.20      0.000     0.000     0.000     0.000        1   Module#attr_writer
  0.18      0.000     0.000     0.000     0.000        1   Grape::Middleware::Error#initialize
  0.18      0.002     0.000     0.000     0.002        1   Grape::Middleware::Formatter#build_formatted_response
  0.17      0.000     0.000     0.000     0.000       29   Kernel#block_given?
  0.17      0.015     0.000     0.000     0.015        1   <Class::Grape::API::Instance>#call!
  0.16      0.006     0.000     0.000     0.006       11  *Thread::Mutex#synchronize
  0.15      0.000     0.000     0.000     0.000       56  *Grape::Util::StackableValues#[]
  0.15      0.000     0.000     0.000     0.000       42   <Class::Mustermann::AST::Node>#[]
  0.14      0.000     0.000     0.000     0.000        5   String#capitalize!
  0.14      0.000     0.000     0.000     0.000        5   Grape::Middleware::Formatter#request
  0.14      0.000     0.000     0.000     0.000       12  *Kernel#dup
  0.14      0.000     0.000     0.000     0.000       34   Mustermann::AST::Node#is_a?
  0.14      0.000     0.000     0.000     0.000        1   String#scan
  0.13      0.000     0.000     0.000     0.000        1   Grape::Endpoint#befores
  0.13      0.000     0.000     0.000     0.000       18   Mustermann::AST::Parser#min_size
  0.13      0.000     0.000     0.000     0.000       15   ActiveSupport::HashWithIndifferentAccess#convert_value
  0.12      0.000     0.000     0.000     0.000       16   Class#inherited
  0.12      0.000     0.000     0.000     0.000       56   Hash#key?
  0.12      0.000     0.000     0.000     0.000       36   Mustermann::AST::Parser#pos
  0.12      0.000     0.000     0.000     0.000       15   BasicObject#singleton_method_added
  0.12      0.000     0.000     0.000     0.000       13   Mustermann::AST::Parser#scan
  0.11      0.000     0.000     0.000     0.000        5   Module#attr_reader
  0.11      0.000     0.000     0.000     0.000        1   <Module::Grape::Extensions::DeepHashWithIndifferentAccess>#deep_hash_with_indifferent_access
  0.11      0.000     0.000     0.000     0.000       19   ActiveSupport::HashWithIndifferentAccess#convert_key
  0.11      0.000     0.000     0.000     0.000       62   Mustermann::AST::Translator::NodeTranslator#__getobj__
  0.11      0.002     0.000     0.000     0.002       17  *Hash#each
  0.11      0.000     0.000     0.000     0.000       31   NilClass#nil?
  0.11      0.000     0.000     0.000     0.000       13   StringScanner#scan
  0.11      0.001     0.000     0.000     0.001        1   <Module::Grape::Formatter>#builtin_formmaters
  0.11      0.000     0.000     0.000     0.000       14   Concurrent::Map#[]
  0.10      0.000     0.000     0.000     0.000        1   Grape::DSL::InsideRoute#status
  0.10      0.000     0.000     0.000     0.000        5   ActiveSupport::HashWithIndifferentAccess#initialize
  0.10      0.000     0.000     0.000     0.000       42   String#to_s
  0.10      0.000     0.000     0.000     0.000       20   Rack::Request::Env#get_header
  0.10      0.000     0.000     0.000     0.000       29   Grape::DSL::Settings#inheritable_setting
  0.09      0.003     0.000     0.000     0.003        1   Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder#build_params
  0.09      0.000     0.000     0.000     0.000       11   Regexp#initialize
  0.09      0.000     0.000     0.000     0.000       36   StringScanner#pos
  0.08      0.002     0.000     0.000     0.002        1   Grape::Middleware::Formatter#after
  0.08      0.000     0.000     0.000     0.000        5   Grape::Endpoint#run_filters
  0.08      0.000     0.000     0.000     0.000        9   ActiveSupport::Notifications::Fanout#listeners_for
  0.08      0.000     0.000     0.000     0.000        7   ActiveSupport::HashWithIndifferentAccess#update
  0.08      0.000     0.000     0.000     0.000        5   Mutex_m#mu_synchronize
  0.08      0.000     0.000     0.000     0.000       74   BasicObject#equal?
  0.08      0.001     0.000     0.000     0.001       74  *Mustermann::AST::Translator#translate
  0.08      0.001     0.000     0.000     0.001        1   Grape::Middleware::Formatter#fetch_formatter
  0.08      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#ensure_content_type
  0.08      0.000     0.000     0.000     0.000        3   Grape::Middleware::Base#content_type_for
  0.08      0.000     0.000     0.000     0.000       10   Mustermann::AST::Boundaries#set_boundaries
  0.07      0.000     0.000     0.000     0.000        6   Module#append_features
  0.07      0.000     0.000     0.000     0.000        1   Rack::Response#initialize
  0.07      0.000     0.000     0.000     0.000        5   Rack::Request::Helpers#request_method
  0.07      0.000     0.000     0.000     0.000        8  *Mustermann::AST::Parser#read
  0.07      0.000     0.000     0.000     0.000        9   ActiveSupport::Notifications::Fanout#listening?
  0.07      0.002     0.000     0.000     0.002        1   Mustermann::EqualityMap#fetch
  0.07      0.000     0.000     0.000     0.000        8   String#%
  0.07      0.000     0.000     0.000     0.000        2   Grape::DSL::InsideRoute#cookies
  0.07      0.000     0.000     0.000     0.000        1   Grape::Request#headers
  0.07      0.000     0.000     0.000     0.000        1   Grape::Middleware::Error#default_options
  0.07      0.000     0.000     0.000     0.000        2   Grape::Middleware::Base#initialize
  0.07      0.000     0.000     0.000     0.000        7   Grape::DSL::Settings#namespace_stackable
  0.06      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#cookies
  0.06      0.000     0.000     0.000     0.000       11   Grape::DSL::Settings#namespace_inheritable
  0.06      0.000     0.000     0.000     0.000        2  *Mustermann::AST::Transformer::GroupTransformer#translate
  0.06      0.007     0.000     0.000     0.007        1   Grape::Middleware::Base#call!
  0.06      0.000     0.000     0.000     0.000        8   Mustermann::AST::Transformer::ArrayTransform#track
  0.06      0.000     0.000     0.000     0.000        8   <Class::Mustermann::AST::Parser>#suffix
  0.06      0.000     0.000     0.000     0.000        2   <Class::Grape::Router>#normalize_path
  0.06      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#POST
  0.06      0.000     0.000     0.000     0.000        4   <Module::Grape::ContentTypes>#content_types_for
  0.06      0.000     0.000     0.000     0.000       10   String#split
  0.06      0.000     0.000     0.000     0.000        6   Array#select
  0.06      0.000     0.000     0.000     0.000       11   Grape::Util::InheritableValues#[]
  0.06      0.001     0.000     0.000     0.001       10  *Delegator#method_missing
  0.06      0.000     0.000     0.000     0.000        8   Mustermann::AST::Parser#read_suffix
  0.06      0.000     0.000     0.000     0.000        4   Grape::Middleware::Base#content_types
  0.05      0.000     0.000     0.000     0.000        1   Hash#select
  0.05      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#format_from_header
  0.05      0.007     0.000     0.000     0.007        2  *Grape::Middleware::Base#call
  0.05      0.000     0.000     0.000     0.000       33  *Grape::Util::InheritableValues#merge
  0.05      0.000     0.000     0.000     0.000        3   Module#extend_object
  0.05      0.000     0.000     0.000     0.000        3   Grape::Middleware::Stack#use
  0.05      0.001     0.000     0.000     0.001       81  *Mustermann::AST::Translator::NodeTranslator#t
  0.05      0.000     0.000     0.000     0.000        4   Array#sort
  0.05      0.000     0.000     0.000     0.000        1   Grape::API::Instance#cascade?
  0.05      0.000     0.000     0.000     0.000        1   Grape::DSL::InsideRoute#file
  0.05      0.000     0.000     0.000     0.000        1   Grape::Request#grape_routing_args
  0.05      0.000     0.000     0.000     0.000        5   Concurrent::Collection::NonConcurrentMapBackend#[]=
  0.05      0.007     0.000     0.000     0.007        1   Grape::Endpoint#call!
  0.05      0.000     0.000     0.000     0.000        3   Kernel#extend
  0.05      0.015     0.000     0.000     0.015        1   Grape::Router#process_route
  0.05      0.000     0.000     0.000     0.000        1   Grape::Request#initialize
  0.05      0.000     0.000     0.000     0.000        6   Mustermann::AST::Parser#default_node
  0.05      0.000     0.000     0.000     0.000       10   Mustermann::AST::Node#initialize
  0.05      0.000     0.000     0.000     0.000        3   Rack::Request::Helpers#query_string
  0.05      0.000     0.000     0.000     0.000        3   ActiveSupport::HashWithIndifferentAccess#[]
  0.05      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#format_from_params
  0.05      0.000     0.000     0.000     0.000        7  *Kernel#tap
  0.05      0.000     0.000     0.000     0.000        3  *Mustermann::AST::Node#parse
  0.05      0.000     0.000     0.000     0.000       25   Kernel#nil?
  0.05      0.000     0.000     0.000     0.000        2   Grape::Router#extract_input_and_method
  0.05      0.000     0.000     0.000     0.000        1   Grape::Middleware::Base#merge_headers
  0.05      0.004     0.000     0.000     0.004        1   Grape::Endpoint#run
  0.05      0.000     0.000     0.000     0.000        5   Hash#default_proc
  0.05      0.000     0.000     0.000     0.000       15   ActiveSupport::HashWithIndifferentAccess#regular_writer
  0.05      0.000     0.000     0.000     0.000        2   Rack::QueryParser#parse_nested_query
  0.05      0.000     0.000     0.000     0.000        7   Array#include?
  0.05      0.000     0.000     0.000     0.000        1   Mustermann::AST::Validation#check_name
  0.05      0.000     0.000     0.000     0.000       11   Mustermann::AST::Transformer::ArrayTransform#lookahead_buffer
  0.05      0.000     0.000     0.000     0.000        8  *#<Class:0x0055b87dd093d8>#translate
  0.05      0.015     0.000     0.000     0.015        1   Grape::Router#transaction
  0.04      0.000     0.000     0.000     0.000        2   Rack::Request::Helpers#media_type
  0.04      0.000     0.000     0.000     0.000       14   Concurrent::Collection::NonConcurrentMapBackend#[]
  0.04      0.000     0.000     0.000     0.000        8   Mustermann::AST::Parser#getch
  0.04      0.000     0.000     0.000     0.000        1   Grape::Cookies#initialize
  0.04      0.000     0.000     0.000     0.000       33   String#start_with?
  0.04      0.000     0.000     0.000     0.000        6   Hash#initialize
  0.04      0.007     0.000     0.000     0.007        1   Rack::Head#call
  0.04      0.000     0.000     0.000     0.000        8   Mustermann::AST::Transformer::ArrayTransform#expect_lookahead?
  0.04      0.000     0.000     0.000     0.000        8   Mustermann::AST::Transformer::ArrayTransform#list_for
  0.04      0.000     0.000     0.000     0.000        8   StringScanner#getch
  0.04      0.000     0.000     0.000     0.000        1   Rack::Response#finish
  0.04      0.001     0.000     0.000     0.001        1   <Module::Grape::Formatter>#formatter_for
  0.04      0.000     0.000     0.000     0.000        4   Grape::DSL::Headers#header
  0.04      0.000     0.000     0.000     0.000        1   Grape::Endpoint#run_validators
  0.04      0.000     0.000     0.000     0.000        4   Array#join
  0.04      0.000     0.000     0.000     0.000        5   Concurrent::Collection::MriMapBackend#[]=
  0.04      0.000     0.000     0.000     0.000        1   Grape::Middleware::Stack#build
  0.04      0.000     0.000     0.000     0.000        7   Grape::DSL::Settings#namespace_stackable_with_hash
  0.04      0.000     0.000     0.000     0.000        2   Module#silence_redefinition_of_method
  0.04      0.000     0.000     0.000     0.000        6   Module#include
  0.04      0.000     0.000     0.000     0.000        2   Array#==
  0.04      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::Pattern>#parser
  0.04      0.002     0.000     0.000     0.002        5  *Array#map
  0.04      0.002     0.000     0.000     0.002        1   Grape::Router::Pattern#params
  0.04      0.000     0.000     0.000     0.000        2   Rack::Request::Env#initialize
  0.04      0.000     0.000     0.000     0.000       44  *Grape::Util::InheritableValues#values
  0.04      0.002     0.000     0.000     0.002        1   Mustermann::Pattern#params
  0.04      0.001     0.000     0.000     0.001        1   <Module::Grape::Formatter>#formatters
  0.03      0.000     0.000     0.000     0.000        5   String#downcase
  0.03      0.000     0.000     0.000     0.000        5   <Module::Grape::DSL::InsideRoute>#post_filter_methods
  0.03      0.000     0.000     0.000     0.000       12   Hash#to_hash
  0.03      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#path
  0.03      0.000     0.000     0.000     0.000        8   Module#private
  0.03      0.000     0.000     0.000     0.000        9   Mustermann::AST::Transformer::ArrayTransform#payload
  0.03      0.000     0.000     0.000     0.000        6   BasicObject#initialize
  0.03      0.000     0.000     0.000     0.000        1   String#bytesize
  0.03      0.000     0.000     0.000     0.000        2   Rack::Response#get_header
  0.03      0.000     0.000     0.000     0.000        1   Rack::Response#write
  0.03      0.000     0.000     0.000     0.000        1   Rack::Utils::HeaderHash#initialize
  0.03      0.000     0.000     0.000     0.000        1   Array#collect
  0.03      0.000     0.000     0.000     0.000        1   Grape::Cookies#write
  0.03      0.000     0.000     0.000     0.000        2   <Class::Grape::Endpoint>#before_each
  0.03      0.000     0.000     0.000     0.000        3   Rack::Request::Env#set_header
  0.03      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#GET
  0.03      0.003     0.000     0.000     0.003        2  *Grape::Request#params
  0.03      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#read_body_input
  0.03      0.000     0.000     0.000     0.000        4   Object#present?
  0.03      0.000     0.000     0.000     0.000        6   Module#included
  0.03      0.000     0.000     0.000     0.000        1   Mustermann::Pattern#map_param
  0.03      0.000     0.000     0.000     0.000       10  *#<Class:0x0055b87dd94410>#translate
  0.03      0.015     0.000     0.000     0.015        1   Grape::API::Instance#call
  0.03      0.000     0.000     0.000     0.000        1   Grape::Middleware::Base#mime_types
  0.03      0.000     0.000     0.000     0.000        1   #<Class:0x0055b87d4edf78>#GET   pong
  0.03      0.000     0.000     0.000     0.000        1   Enumerable#sort_by
  0.03      0.000     0.000     0.000     0.000        2   Mustermann::AST::Transformer::ArrayTransform#create_lookahead
  0.03      0.000     0.000     0.000     0.000        7   Mustermann::AST::Parser#eos?
  0.03      0.000     0.000     0.000     0.000       10  *Mustermann::AST::Parser#node
  0.03      0.007     0.000     0.000     0.007        1   Grape::Middleware::Error#call!
  0.03      0.000     0.000     0.000     0.000        3   Kernel#initialize_copy
  0.03      0.000     0.000     0.000     0.000        2   Grape::Middleware::Stack#merge_with
  0.03      0.000     0.000     0.000     0.000        3   Grape::Middleware::Stack::Middleware#initialize
  0.03      0.013     0.000     0.000     0.013        1   Grape::Endpoint#call
  0.03      0.000     0.000     0.000     0.000        1   Mustermann::Grape::Parser#read "("
  0.03      0.000     0.000     0.000     0.000        1   Grape::Router#cascade?
  0.03      0.000     0.000     0.000     0.000        1   Rack::BodyProxy#initialize
  0.03      0.000     0.000     0.000     0.000        1   Rack::Utils::HeaderHash#initialize_copy
  0.03      0.000     0.000     0.000     0.000        1   Grape::Util::Registrable#default_elements
  0.03      0.000     0.000     0.000     0.000        1   Grape::Endpoint#finallies
  0.03      0.000     0.000     0.000     0.000        2  *<Class::Grape::Endpoint>#run_before_each
  0.03      0.000     0.000     0.000     0.000        4   String#[]
  0.03      0.000     0.000     0.000     0.000        2   <Class::Rack::MediaType>#type
  0.03      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#parse_query
  0.03      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#params
  0.03      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#put?
  0.03      0.000     0.000     0.000     0.000       19   Kernel#kind_of?
  0.03      0.000     0.000     0.000     0.000        1   <Module::Rack::Utils>#parse_nested_query
  0.03      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#script_name
  0.03      0.000     0.000     0.000     0.000        2   Rack::Request#initialize
  0.03      0.000     0.000     0.000     0.000        1   Rack::Head#initialize
  0.03      0.000     0.000     0.000     0.000        1   Rack::Builder#to_app
  0.03      0.000     0.000     0.000     0.000        1   Rack::Builder#initialize
  0.03      0.000     0.000     0.000     0.000        8   Array#blank?
  0.03      0.000     0.000     0.000     0.000        5   Module#module_function
  0.03      0.000     0.000     0.000     0.000        6   Array#first
  0.03      0.000     0.000     0.000     0.000        1   #<Class:0x0055b87dcc5ae8>#translate
  0.03      0.000     0.000     0.000     0.000        2  *#<Class:0x0055b87dcc6498>#translate
  0.03      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#scan_params
  0.03      0.000     0.000     0.000     0.000        2  *#<Class:0x0055b87dcf0fb8>#translate
  0.03      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::Validation>#validate
  0.03      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#set_boundaries
  0.03      0.000     0.000     0.000     0.000        4   Kernel#Array
  0.03      0.015     0.000     0.000     0.015        1   Grape::Router#with_optimization
  0.03      0.000     0.000     0.000     0.000        2   Rack::Utils::HeaderHash#[]=
  0.03      0.000     0.000     0.000     0.000        2   Rack::Utils::HeaderHash#merge!
  0.03      0.000     0.000     0.000     0.000        1   Grape::DSL::InsideRoute#body
  0.03      0.000     0.000     0.000     0.000        1   Grape::Endpoint#afters
  0.03      0.000     0.000     0.000     0.000        2   Grape::DSL::Settings#route_setting
  0.03      0.000     0.000     0.000     0.000        1   Grape::Endpoint#before_validations
  0.03      0.000     0.000     0.000     0.000        1   Hash#fetch
  0.03      0.000     0.000     0.000     0.000        1   Enumerable#flat_map
  0.03      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#mime_array
  0.03      0.000     0.000     0.000     0.000        9   Hash#[]
  0.03      0.000     0.000     0.000     0.000        6   Hash#default
  0.03      0.000     0.000     0.000     0.000        3   Module#alias_method
  0.03      0.000     0.000     0.000     0.000        3   Array#push
  0.03      0.000     0.000     0.000     0.000        2   Array#flatten!
  0.03      0.000     0.000     0.000     0.000        2   <Class::Delegator>#const_missing
  0.03      0.002     0.000     0.000     0.002        1   Mustermann::AST::Pattern#param_converters
  0.03      0.000     0.000     0.000     0.000        1   Grape::Router#match?
  0.02      0.000     0.000     0.000     0.000        4   Array#uniq
  0.02      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#form_data?
  0.02      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#negotiate_content_type
  0.02      0.000     0.000     0.000     0.000        8   String#inspect
  0.02      0.000     0.000     0.000     0.000        1   Kernel#lambda
  0.02      0.000     0.000     0.000     0.000        1   <Class::Rack::Utils::HeaderHash>#new
  0.02      0.000     0.000     0.000     0.000        1   Set#include?
  0.02      0.000     0.000     0.000     0.000        1   UnboundMethod#bind
  0.02      0.000     0.000     0.000     0.000        1   Grape::Endpoint#remove_renamed_params
  0.02      0.000     0.000     0.000     0.000        1   Grape::Endpoint#validations
  0.02      0.000     0.000     0.000     0.000        1   Grape::Request#build_headers
  0.02      0.000     0.000     0.000     0.000        2   Hash#delete
  0.02      0.000     0.000     0.000     0.000        1   <Class::ActiveSupport::HashWithIndifferentAccess>#[]
  0.02      0.000     0.000     0.000     0.000        2   Rack::Request::Helpers#content_type
  0.02      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#query_parser
  0.02      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#delete?
  0.02      0.000     0.000     0.000     0.000        1   ActiveSupport::HashWithIndifferentAccess#default
  0.02      0.000     0.000     0.000     0.000        3   Rack::Builder#use
  0.02      0.000     0.000     0.000     0.000        1   Grape::Middleware::Stack#concat
  0.02      0.000     0.000     0.000     0.000        1   Class#initialize
  0.02      0.000     0.000     0.000     0.000        1   Array#flatten
  0.02      0.000     0.000     0.000     0.000        6   #<Class:0x0055b87dcc5f20>#translate
  0.02      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#validate
  0.02      0.000     0.000     0.000     0.000        7   #<Class:0x0055b87dd8f938>#translate
  0.02      0.000     0.000     0.000     0.000        2  *#<Class:0x0055b87dd8fc30>#translate
  0.02      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#boundaries
  0.02      0.000     0.000     0.000     0.000        2   #<Class:0x0055b87dd96968>#payload=
  0.02      0.000     0.000     0.000     0.000        2  *Mustermann::AST::Transformer::ArrayTransform#translate
  0.02      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#transformer
  0.02      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#parse
  0.02      0.000     0.000     0.000     0.000        3   String#hash
  0.02      0.002     0.000     0.000     0.002        1   Mustermann::AST::Pattern#map_param
  0.02      0.000     0.000     0.000     0.000        3   Fixnum#to_s
  0.02      0.000     0.000     0.000     0.000        2   Grape::Router#string_for
  0.02      0.000     0.000     0.000     0.000        4  *Grape::Util::InheritableValues#keys
  0.02      0.000     0.000     0.000     0.000        1   Rack::Response#set_header
  0.02      0.000     0.000     0.000     0.000        3   Rack::Utils::HeaderHash#[]
  0.02      0.000     0.000     0.000     0.000        2   String#freeze
  0.02      0.000     0.000     0.000     0.000        1   Rack::Utils::HeaderHash#merge
  0.02      0.000     0.000     0.000     0.000        1   <Module::Grape::Formatter::Txt>#call
  0.02      0.000     0.000     0.000     0.000        1   <Module::Grape>#config
  0.02      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#post?
  0.02      0.000     0.000     0.000     0.000        4   NilClass#blank?
  0.02      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#path_info
  0.02      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#before
  0.02      0.007     0.000     0.000     0.007        1   Kernel#catch
  0.02      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#default_options
  0.02      0.000     0.000     0.000     0.000        1   Rack::Builder#run
  0.02      0.000     0.000     0.000     0.000        3   Module#extended
  0.02      0.000     0.000     0.000     0.000        1   Grape::Endpoint#build_helpers
  0.02      0.013     0.000     0.000     0.013        1   Grape::Router::Route#exec
  0.02      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#param_scanner
  0.02      0.000     0.000     0.000     0.000        4   Kernel#proc
  0.02      0.000     0.000     0.000     0.000        1   Mustermann::EqualityMap#track
  0.02      0.000     0.000     0.000     0.000        1   #<Class:0x0055b87dcf0d38>#translate
  0.02      0.000     0.000     0.000     0.000        6   #<Class:0x0055b87dcf17d8>#translate
  0.02      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#validation
  0.02      0.000     0.000     0.000     0.000        7   #<Class:0x0055b87dd08ff0>#translate
  0.02      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#transform
  0.02      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::Parser>#parse
  0.02      0.000     0.000     0.000     0.000        3   Module#const_get
  0.02      0.002     0.000     0.000     0.002        1   Grape::Router::Route#params
  0.02      0.002     0.000     0.000     0.002        1   Grape::Router#make_routing_args
  0.02      0.000     0.000     0.000     0.000        2   String#sub!
  0.01      0.000     0.000     0.000     0.000        5   Hash#keys
  0.01      0.000     0.000     0.000     0.000        2   Hash#[]=
  0.01      0.000     0.000     0.000     0.000        1   Rack::Utils::HeaderHash#names
  0.01      0.000     0.000     0.000     0.000        2   String#===
  0.01      0.000     0.000     0.000     0.000        1   String#upcase
  0.01      0.000     0.000     0.000     0.000        1   Method#call
  0.01      0.000     0.000     0.000     0.000        1   Rack::Request::Env#fetch_header
  0.01      0.000     0.000     0.000     0.000        6   String#==
  0.01      0.000     0.000     0.000     0.000        1   Array#shift
  0.01      0.000     0.000     0.000     0.000        1   Module#protected
  0.01      0.000     0.000     0.000     0.000        1   Hash#each_key
  0.01      0.000     0.000     0.000     0.000        1   Hash#symbolize_keys
  0.01      0.000     0.000     0.000     0.000        1   Hash#delete_if
  0.01      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::Pattern>#param_scanner
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::EqualityMap#finalizer
  0.01      0.000     0.000     0.000     0.000        2   Mustermann::AST::Validation#names
  0.01      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::Transformer>#transform
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::Grape::Parser#read ":"
  0.01      0.000     0.000     0.000     0.000       13   Regexp#names
  0.01      0.000     0.000     0.000     0.000       11   <Class::Regexp>#escape
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::AST::Parser#initialize
  0.01      0.002     0.000     0.000     0.002        1   Mustermann::AST::Pattern#to_ast
  0.01      0.000     0.000     0.000     0.000        2   Symbol#<=>
  0.01      0.000     0.000     0.000     0.000        3   Integer#to_i
  0.01      0.000     0.000     0.000     0.000        2   NilClass#===
  0.01      0.000     0.000     0.000     0.000        1   Grape::Endpoint#after_validations
  0.01      0.000     0.000     0.000     0.000        1   Class#superclass
  0.01      0.000     0.000     0.000     0.000        6   Module#===
  0.01      0.000     0.000     0.000     0.000        1   Hash#deep_merge!
  0.01      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#format_from_extension
  0.01      0.000     0.000     0.000     0.000        1   Array#reverse
  0.01      0.000     0.000     0.000     0.000        1   Method#to_proc
  0.01      0.000     0.000     0.000     0.000        1   Kernel#method
  0.01      0.000     0.000     0.000     0.000        1   Array#reject
  0.01      0.000     0.000     0.000     0.000        1   Grape::DSL::Settings#namespace_reverse_stackable_with_hash
  0.01      0.000     0.000     0.000     0.000        1   Kernel#singleton_class
  0.01      0.000     0.000     0.000     0.000        1   Grape::Middleware::Stack#initialize
  0.01      0.000     0.000     0.000     0.000        1   Module#initialize
  0.01      0.006     0.000     0.000     0.006        1   Grape::Endpoint#lazy_initialize!
  0.01      0.000     0.000     0.000     0.000        1   Hash#transform_keys
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::Pattern#always_array?
  0.01      0.000     0.000     0.000     0.000        1   <Module::ObjectSpace>#define_finalizer
  0.01      0.000     0.000     0.000     0.000        9  *#<Class:0x0055b87dcf12d8>#translate
  0.01      0.000     0.000     0.000     0.000        1   Kernel#public_send
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::AST::Node::Composition#initialize
  0.01      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::Node::Root>#parse
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::AST::Parser#parse
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#parser
  0.01      0.000     0.000     0.000     0.000        2   String#squeeze!
  0.01      0.015     0.000     0.000     0.015        1   Grape::Router#identity
  0.01      0.015     0.000     0.000     0.015        1   Grape::Router#call
  0.01      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#parseable_data?
  0.01      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#patch?
  0.01      0.000     0.000     0.000     0.000        2   Module#method_defined?
  0.01      0.000     0.000     0.000     0.000        1   StringScanner#initialize
  0.01      0.000     0.000     0.000     0.000        1   ObjectSpace::WeakMap#[]
  0.01      0.002     0.000     0.000     0.002        1   Enumerable#map
  0.01      0.000     0.000     0.000     0.000        2   Rack::Response#chunked?
  0.01      0.000     0.000     0.000     0.000        4  *Grape::Util::ReverseStackableValues#[]
  0.01      0.000     0.000     0.000     0.000        1   Module#private_method_defined?
  0.01      0.000     0.000     0.000     0.000        2   <Class::Hash>#[]
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::Pattern#unescape
  0.01      0.000     0.000     0.000     0.000        1   Hash#include?
  0.01      0.000     0.000     0.000     0.000        9  *#<Class:0x0055b87dcc6790>#translate
  0.01      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::ParamScanner>#scan_params
  0.01      0.000     0.000     0.000     0.000        1   ObjectSpace::WeakMap#[]=
  0.01      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::Pattern>#validation
  0.01      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::Boundaries>#set_boundaries
  0.01      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::Pattern>#boundaries
  0.01      0.000     0.000     0.000     0.000        2   #<Module:0x0055b87d5b1478>#is_a?
  0.01      0.000     0.000     0.000     0.000        1   <Class::Mustermann::AST::Pattern>#transformer
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::AST::Node::Capture#parse
  0.01      0.000     0.000     0.000     0.000        1   NilClass#to_a
  0.01      0.000     0.000     0.000     0.000        2  *<Class::Mustermann::AST::Node>#parse
  0.01      0.000     0.000     0.000     0.000        7   StringScanner#eos?
  0.01      0.000     0.000     0.000     0.000        1   Module#const_defined?
  0.01      0.000     0.000     0.000     0.000        2   Kernel#frozen?
  0.01      0.000     0.000     0.000     0.000        1   Regexp#named_captures
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::RegexpBased#named_captures
  0.01      0.000     0.000     0.000     0.000        1   Mustermann::RegexpBased#match
  0.01      0.000     0.000     0.000     0.000        3   MatchData#[]
  0.01      0.000     0.000     0.000     0.000        1   Enumerable#detect
  0.01      0.000     0.000     0.000     0.000        1   <Class::Regexp>#last_match
  0.00      0.000     0.000     0.000     0.000        2   BasicObject#==

2nd call

Sort by: self_time

 %self      total      self      wait     child     calls  name
  7.98      0.001     0.000     0.000     0.000        1   Grape::Endpoint#run
  3.31      0.000     0.000     0.000     0.000        9   Hash#each_pair
  2.21      0.000     0.000     0.000     0.000        9  *<Module::ActiveSupport::Notifications>#instrument
  1.94      0.000     0.000     0.000     0.000        9   Grape::DSL::Settings#get_or_set
  1.66      0.000     0.000     0.000     0.000       19   ActiveSupport::HashWithIndifferentAccess#convert_key
  1.61      0.000     0.000     0.000     0.000       17   Array#each
  1.57      0.000     0.000     0.000     0.000       40   Array#concat
  1.48      0.000     0.000     0.000     0.000       20  *Kernel#initialize_dup
  1.41      0.000     0.000     0.000     0.000        5   ActiveSupport::HashWithIndifferentAccess#initialize
  1.41      0.000     0.000     0.000     0.000       17   Hash#initialize_copy
  1.30      0.000     0.000     0.000     0.000       13   Hash#merge
  1.26      0.000     0.000     0.000     0.000       20   Rack::Request::Env#get_header
  1.19      0.000     0.000     0.000     0.000        9   ActiveSupport::Notifications::Fanout#listeners_for
  1.15      0.000     0.000     0.000     0.000       15   ActiveSupport::HashWithIndifferentAccess#convert_value
  1.13      0.000     0.000     0.000     0.000       42   String#to_s
  1.10      0.000     0.000     0.000     0.000       11  *Class#new
  1.02      0.001     0.000     0.000     0.001        1   <Class::Grape::API::Instance>#call!
  0.86      0.000     0.000     0.000     0.000        7   Hash#each
  0.84      0.000     0.000     0.000     0.000       12   Hash#to_hash
  0.80      0.000     0.000     0.000     0.000        5   Grape::Endpoint#run_filters
  0.80      0.000     0.000     0.000     0.000        5   Grape::DSL::Settings#namespace_stackable
  0.77      0.000     0.000     0.000     0.000       17   Symbol#to_s
  0.75      0.000     0.000     0.000     0.000       15   ActiveSupport::HashWithIndifferentAccess#regular_writer
  0.75      0.000     0.000     0.000     0.000        3   Grape::Middleware::Base#content_type_for
  0.73      0.000     0.000     0.000     0.000        1   Grape::DSL::InsideRoute#status
  0.73      0.000     0.000     0.000     0.000        7   ActiveSupport::HashWithIndifferentAccess#update
  0.73      0.000     0.000     0.000     0.000       28   Kernel#block_given?
  0.71      0.000     0.000     0.000     0.000        6   Hash#initialize
  0.64      0.000     0.000     0.000     0.000        9   Hash#[]
  0.64      0.000     0.000     0.000     0.000       10   String#split
  0.57      0.000     0.000     0.000     0.000       20   Hash#key?
  0.55      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#build_formatted_response
  0.55      0.000     0.000     0.000     0.000       10   Array#any?
  0.55      0.000     0.000     0.000     0.000        9   Concurrent::Collection::NonConcurrentMapBackend#[]
  0.55      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#read_body_input
  0.55      0.000     0.000     0.000     0.000        4   <Module::Grape::ContentTypes>#content_types_for
  0.55      0.000     0.000     0.000     0.000        5   Grape::Middleware::Formatter#request
  0.55      0.001     0.000     0.000     0.001        1   Grape::Middleware::Base#call!
  0.55      0.000     0.000     0.000     0.000        3   Array#map
  0.53      0.000     0.000     0.000     0.000        4   Grape::Middleware::Base#content_types
  0.53      0.000     0.000     0.000     0.000        4   Kernel#nil?
  0.53      0.000     0.000     0.000     0.000        2   Grape::Router#extract_input_and_method
  0.51      0.001     0.000     0.000     0.001        1   Grape::Router#transaction
  0.49      0.000     0.000     0.000     0.000        1   Grape::Middleware::Base#merge_headers
  0.49      0.000     0.000     0.000     0.000        1   Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder#build_params
  0.49      0.000     0.000     0.000     0.000        9   ActiveSupport::Notifications::Fanout#listening?
  0.49      0.000     0.000     0.000     0.000       41   Kernel#is_a?
  0.49      0.000     0.000     0.000     0.000        8   Kernel#respond_to?
  0.49      0.000     0.000     0.000     0.000       12   NilClass#nil?
  0.46      0.000     0.000     0.000     0.000        4   Array#uniq
  0.46      0.000     0.000     0.000     0.000        2   Rack::Utils::HeaderHash#[]=
  0.46      0.000     0.000     0.000     0.000        1   Rack::Response#initialize
  0.46      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#fetch_formatter
  0.46      0.000     0.000     0.000     0.000        2   Module#extend_object
  0.46      0.000     0.000     0.000     0.000        8  *Grape::Util::InheritableValues#values
  0.46      0.000     0.000     0.000     0.000       10   Grape::DSL::Settings#inheritable_setting
  0.46      0.000     0.000     0.000     0.000        9   Concurrent::Map#[]
  0.46      0.001     0.000     0.000     0.001        1   Kernel#catch
  0.46      0.000     0.000     0.000     0.000        7  *Kernel#dup
  0.46      0.000     0.000     0.000     0.000        6   Array#first
  0.46      0.000     0.000     0.000     0.000        1   Grape::Router::Pattern#params
  0.46      0.000     0.000     0.000     0.000        3   MatchData#[]
  0.44      0.000     0.000     0.000     0.000       20  *Grape::Util::StackableValues#[]
  0.44      0.000     0.000     0.000     0.000        6   Module#===
  0.44      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#GET
  0.40      0.000     0.000     0.000     0.000        4   String#[]
  0.38      0.000     0.000     0.000     0.000        4   Array#sort
  0.38      0.000     0.000     0.000     0.000        3   Rack::Utils::HeaderHash#[]
  0.38      0.000     0.000     0.000     0.000        1   Rack::Response#write
  0.38      0.000     0.000     0.000     0.000        1   Kernel#lambda
  0.38      0.000     0.000     0.000     0.000        1   <Module::Grape::Formatter>#formatter_for
  0.38      0.000     0.000     0.000     0.000        1   Grape::DSL::InsideRoute#file
  0.38      0.000     0.000     0.000     0.000        1   Grape::Cookies#initialize
  0.38      0.000     0.000     0.000     0.000        1   String#scan
  0.38      0.000     0.000     0.000     0.000        1   Mustermann::Pattern#params
  0.38      0.000     0.000     0.000     0.000        1   Grape::Router#match?
  0.38      0.000     0.000     0.000     0.000        5   Kernel#class
  0.35      0.000     0.000     0.000     0.000        4  *Grape::Util::InheritableValues#keys
  0.35      0.000     0.000     0.000     0.000        5   String#downcase
  0.35      0.000     0.000     0.000     0.000        4   Grape::DSL::Headers#header
  0.35      0.000     0.000     0.000     0.000        2   Grape::DSL::Settings#route_setting
  0.35      0.000     0.000     0.000     0.000        6   String#==
  0.35      0.000     0.000     0.000     0.000        2   <Class::Rack::MediaType>#type
  0.35      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#POST
  0.35      0.000     0.000     0.000     0.000        2  *Grape::Request#params
  0.35      0.000     0.000     0.000     0.000        5   Rack::Request::Helpers#request_method
  0.35      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#format_from_params
  0.35      0.001     0.000     0.000     0.001        1   Grape::Endpoint#call!
  0.35      0.000     0.000     0.000     0.000        2   Regexp#match
  0.35      0.000     0.000     0.000     0.000        2   <Class::Grape::Router>#normalize_path
  0.31      0.000     0.000     0.000     0.000        2   Rack::Request::Helpers#media_type
  0.31      0.000     0.000     0.000     0.000        4   Object#present?
  0.29      0.000     0.000     0.000     0.000        5   Hash#keys
  0.29      0.000     0.000     0.000     0.000        1   Grape::API::Instance#cascade?
  0.29      0.000     0.000     0.000     0.000        1   Rack::Response#finish
  0.29      0.000     0.000     0.000     0.000        2   Rack::Utils::HeaderHash#merge!
  0.29      0.000     0.000     0.000     0.000        1   Array#collect
  0.29      0.000     0.000     0.000     0.000        1   <Module::Grape::Formatter>#formatters
  0.29      0.000     0.000     0.000     0.000        2   <Class::Grape::Endpoint>#before_each
  0.29      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#cookies
  0.29      0.000     0.000     0.000     0.000        2   Grape::DSL::InsideRoute#cookies
  0.29      0.000     0.000     0.000     0.000        4   Array#join
  0.29      0.000     0.000     0.000     0.000       33   String#start_with?
  0.29      0.000     0.000     0.000     0.000        1   <Module::Grape>#config
  0.29      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#delete?
  0.29      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#post?
  0.29      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#mime_array
  0.29      0.000     0.000     0.000     0.000        2   Rack::Request::Env#initialize
  0.29      0.000     0.000     0.000     0.000        2   Rack::Request#initialize
  0.29      0.001     0.000     0.000     0.001        2  *Grape::Middleware::Base#call
  0.29      0.001     0.000     0.000     0.001        1   Rack::Head#call
  0.29      0.000     0.000     0.000     0.000        3   Kernel#initialize_copy
  0.29      0.001     0.000     0.000     0.001        1   Grape::Endpoint#call
  0.29      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#map_param
  0.29      0.000     0.000     0.000     0.000        1   Grape::Router::Route#params
  0.29      0.000     0.000     0.000     0.000        2   String#sub!
  0.29      0.000     0.000     0.000     0.000        2   String#squeeze!
  0.29      0.001     0.000     0.000     0.001        1   Grape::Router#identity
  0.27      0.000     0.000     0.000     0.000        1   Rack::BodyProxy#initialize
  0.27      0.000     0.000     0.000     0.000        2   Rack::Response#get_header
  0.27      0.000     0.000     0.000     0.000        1   Rack::Utils::HeaderHash#merge
  0.27      0.000     0.000     0.000     0.000        1   <Class::Rack::Utils::HeaderHash>#new
  0.27      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#after
  0.27      0.000     0.000     0.000     0.000        1   Grape::Endpoint#run_validators
  0.27      0.000     0.000     0.000     0.000        5   <Module::Grape::DSL::InsideRoute>#post_filter_methods
  0.27      0.000     0.000     0.000     0.000        2  *<Class::Grape::Endpoint>#run_before_each
  0.27      0.000     0.000     0.000     0.000        1   Hash#fetch
  0.27      0.000     0.000     0.000     0.000        1   Grape::Cookies#read
  0.27      0.000     0.000     0.000     0.000        2   Rack::Request::Helpers#content_type
  0.27      0.000     0.000     0.000     0.000        3   Rack::Request::Env#set_header
  0.27      0.000     0.000     0.000     0.000        2   Kernel#extend
  0.27      0.000     0.000     0.000     0.000        1   Grape::Request#initialize
  0.27      0.000     0.000     0.000     0.000        6  *Grape::Util::InheritableValues#merge
  0.27      0.000     0.000     0.000     0.000        2   Grape::DSL::Settings#namespace_inheritable
  0.27      0.000     0.000     0.000     0.000        6   Hash#default
  0.27      0.000     0.000     0.000     0.000        2   Rack::QueryParser#parse_nested_query
  0.27      0.000     0.000     0.000     0.000        1   Hash#transform_keys
  0.27      0.000     0.000     0.000     0.000        5   Array#include?
  0.27      0.000     0.000     0.000     0.000        1   Enumerable#map
  0.27      0.001     0.000     0.000     0.001        1   Grape::Router#process_route
  0.27      0.001     0.000     0.000     0.001        1   Grape::API::Instance#call
  0.20      0.000     0.000     0.000     0.000        1   String#bytesize
  0.20      0.000     0.000     0.000     0.000        1   Rack::Utils::HeaderHash#initialize
  0.20      0.000     0.000     0.000     0.000        1   <Module::Grape::Formatter::Txt>#call
  0.20      0.000     0.000     0.000     0.000        1   Grape::Endpoint#finallies
  0.20      0.000     0.000     0.000     0.000        1   String#upcase
  0.20      0.000     0.000     0.000     0.000        2   NilClass#===
  0.20      0.000     0.000     0.000     0.000        1   Method#call
  0.20      0.000     0.000     0.000     0.000        1   Grape::Endpoint#before_validations
  0.20      0.000     0.000     0.000     0.000        1   Grape::Endpoint#befores
  0.20      0.000     0.000     0.000     0.000        1   Grape::Request#headers
  0.20      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#form_data?
  0.20      0.000     0.000     0.000     0.000        3   Rack::Request::Helpers#query_string
  0.20      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#params
  0.20      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#format_from_header
  0.20      0.000     0.000     0.000     0.000        1   ActiveSupport::HashWithIndifferentAccess#default
  0.20      0.000     0.000     0.000     0.000        3   ActiveSupport::HashWithIndifferentAccess#[]
  0.20      0.000     0.000     0.000     0.000        1   <Module::Rack::Utils>#parse_nested_query
  0.20      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#path
  0.20      0.000     0.000     0.000     0.000        1   Mustermann::Pattern#unescape
  0.20      0.000     0.000     0.000     0.000        1   Regexp#named_captures
  0.20      0.000     0.000     0.000     0.000        3   Fixnum#to_s
  0.20      0.000     0.000     0.000     0.000        2   Grape::Router#string_for
  0.20      0.001     0.000     0.000     0.001        1   Grape::Router#call
  0.18      0.000     0.000     0.000     0.000        1   Rack::Response#set_header
  0.18      0.000     0.000     0.000     0.000        2   Rack::Response#chunked?
  0.18      0.000     0.000     0.000     0.000        1   Rack::Utils::HeaderHash#initialize_copy
  0.18      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#ensure_content_type
  0.18      0.000     0.000     0.000     0.000        1   Grape::DSL::InsideRoute#body
  0.18      0.000     0.000     0.000     0.000        1   Grape::Cookies#write
  0.18      0.000     0.000     0.000     0.000        1   Grape::Endpoint#afters
  0.18      0.000     0.000     0.000     0.000        1   UnboundMethod#bind
  0.18      0.000     0.000     0.000     0.000        1   Grape::Endpoint#after_validations
  0.18      0.000     0.000     0.000     0.000        1   Grape::Endpoint#remove_renamed_params
  0.18      0.000     0.000     0.000     0.000        1   Grape::Endpoint#validations
  0.18      0.000     0.000     0.000     0.000        1   Rack::Request::Env#fetch_header
  0.18      0.000     0.000     0.000     0.000        1   Enumerable#inject
  0.18      0.000     0.000     0.000     0.000        1   Grape::Request#grape_routing_args
  0.18      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#parse_query
  0.18      0.000     0.000     0.000     0.000        2   Grape::Util::InheritableValues#[]
  0.18      0.000     0.000     0.000     0.000        1   Enumerable#sort_by
  0.18      0.000     0.000     0.000     0.000       19   Kernel#kind_of?
  0.18      0.000     0.000     0.000     0.000        4   NilClass#blank?
  0.18      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#script_name
  0.18      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#format_from_extension
  0.18      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#negotiate_content_type
  0.18      0.001     0.000     0.000     0.001        1   Grape::Router::Route#exec
  0.18      0.000     0.000     0.000     0.000        2   <Class::Hash>#[]
  0.18      0.000     0.000     0.000     0.000        1   Array#flatten
  0.18      0.000     0.000     0.000     0.000        1   Mustermann::Pattern#map_param
  0.18      0.000     0.000     0.000     0.000        1   Grape::Router#make_routing_args
  0.18      0.001     0.000     0.000     0.001        1   Grape::Router#with_optimization
  0.11      0.000     0.000     0.000     0.000        1   Rack::Utils::HeaderHash#names
  0.11      0.000     0.000     0.000     0.000        1   Grape::Middleware::Base#mime_types
  0.11      0.000     0.000     0.000     0.000        1   Hash#select
  0.11      0.000     0.000     0.000     0.000        2   Hash#delete
  0.11      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#query_parser
  0.11      0.000     0.000     0.000     0.000        1   Hash#each_key
  0.09      0.000     0.000     0.000     0.000        2   Symbol#<=>
  0.09      0.000     0.000     0.000     0.000        1   Grape::Router#cascade?
  0.09      0.000     0.000     0.000     0.000        2   Hash#[]=
  0.09      0.000     0.000     0.000     0.000        2   String#freeze
  0.09      0.000     0.000     0.000     0.000        3   Integer#to_i
  0.09      0.000     0.000     0.000     0.000        1   Grape::Util::Registrable#default_elements
  0.09      0.000     0.000     0.000     0.000        1   <Module::Grape::Formatter>#builtin_formmaters
  0.09      0.000     0.000     0.000     0.000        1   Set#include?
  0.09      0.000     0.000     0.000     0.000        1   #<Class:0x0055b87d4edf78>#GET   pong
  0.09      0.000     0.000     0.000     0.000        1   Class#superclass
  0.09      0.000     0.000     0.000     0.000        5   String#capitalize!
  0.09      0.000     0.000     0.000     0.000        1   Grape::Request#build_headers
  0.09      0.000     0.000     0.000     0.000        1   <Module::Grape::Extensions::DeepHashWithIndifferentAccess>#deep_hash_with_indifferent_access
  0.09      0.000     0.000     0.000     0.000        1   Hash#deep_merge!
  0.09      0.000     0.000     0.000     0.000        1   <Class::ActiveSupport::HashWithIndifferentAccess>#[]
  0.09      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#parseable_data?
  0.09      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#patch?
  0.09      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#put?
  0.09      0.000     0.000     0.000     0.000        5   Hash#default_proc
  0.09      0.000     0.000     0.000     0.000        1   Rack::Request::Helpers#path_info
  0.09      0.000     0.000     0.000     0.000        1   Grape::Middleware::Formatter#before
  0.09      0.001     0.000     0.000     0.001        1   Grape::Middleware::Error#call!
  0.09      0.000     0.000     0.000     0.000        1   Hash#symbolize_keys
  0.09      0.000     0.000     0.000     0.000        1   Hash#delete_if
  0.09      0.000     0.000     0.000     0.000        1   Mustermann::Pattern#always_array?
  0.09      0.000     0.000     0.000     0.000        1   Mustermann::AST::Pattern#param_converters
  0.09      0.000     0.000     0.000     0.000        1   Mustermann::RegexpBased#named_captures
  0.09      0.000     0.000     0.000     0.000        1   Mustermann::RegexpBased#match
  0.09      0.000     0.000     0.000     0.000        1   Enumerable#detect
  0.00      0.000     0.000     0.000     0.000        1   BasicObject#==
  0.00      0.000     0.000     0.000     0.000        2   String#===
  0.00      0.000     0.000     0.000     0.000        2   Module#extended
  0.00      0.000     0.000     0.000     0.000        1   Enumerable#flat_map
  0.00      0.000     0.000     0.000     0.000        2   BasicObject#initialize
  0.00      0.000     0.000     0.000     0.000        1   Grape::Endpoint#lazy_initialize!
  0.00      0.000     0.000     0.000     0.000        1   Hash#include?
  0.00      0.000     0.000     0.000     0.000        1   <Class::Regexp>#last_match

@myxoh
Copy link
Member

myxoh commented Sep 3, 2019

OK, having modified the grape.rb file to support eager_load on all modules, and calling eager load on all module basically reduced the difference between both calls to almost 0 (I probably missed some autoloaded classes)

Should we create a PR to add a start_up method that pre-compiles an API and also triggers eager_loading on all grape modules?

@dblock
Copy link
Member

dblock commented Sep 3, 2019

Should we create a PR to add a start_up method that pre-compiles an API and also triggers eager_loading on all grape modules?

Absolutely. I would think a bit harder about naming, maybe compile! or start! or even eager_load?

@myxoh
Copy link
Member

myxoh commented Sep 3, 2019

Opened the PR: #1904 , taking suggestions as to how best to test this

@dblock
Copy link
Member

dblock commented Sep 6, 2019

@viraptor check out master after #1904, thanks @myxoh !

@myxoh
Copy link
Member

myxoh commented Sep 6, 2019

I'd be curious to see whether there's some more work to be done. I'm sure there's still stuff that doesn't happen until runtime, but hopefully that is quite minimal now

@myxoh
Copy link
Member

myxoh commented Oct 4, 2019

Given the lack of response I feel we should probably close this issue, and re open if a new problem arises

@myxoh myxoh closed this as completed Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants