Website build profile
Middleman supports profiling with --profile
, so I generated a profile for a production build. I also monkey-patched it to generate a more detailed call-stack profile rather than the default:
diff --git a/Gemfile b/Gemfile
index 24cba5cc84..c8fc2f8641 100644
--- a/Gemfile
+++ b/Gemfile
@@ -15,6 +15,7 @@ gem 'middleman-livereload'
gem 'middleman-minify-html'
gem 'middleman-autoprefixer', '~> 2.7.1'
gem 'middleman-syntax'
+gem 'ruby-prof'
gem 'kramdown', '~> 1.10'
gem 'nokogiri', '>= 1.8.3'
diff --git a/Gemfile.lock b/Gemfile.lock
index 6fbf5b1941..45f1a43f57 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -197,6 +197,7 @@ GEM
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
+ ruby-prof (0.17.0)
ruby-progressbar (1.10.0)
rubyzip (1.2.2)
sass (3.4.25)
@@ -254,6 +255,7 @@ DEPENDENCIES
nokogiri (>= 1.8.3)
rspec (~> 3.5)
rubocop (~> 0.59.0)
+ ruby-prof
sassc
scss_lint
selenium-webdriver
diff --git a/config.rb b/config.rb
index 2c24d366bf..aacde92366 100644
--- a/config.rb
+++ b/config.rb
@@ -5,6 +5,20 @@ require 'extensions/breadcrumbs'
require 'lib/homepage'
require "thwait"
+class Middleman::Profiling::RubyProfProfiler
+ def report(report_name)
+ result = RubyProf.stop
+
+ printer = RubyProf::CallStackPrinter.new(result)
+ outfile = File.join('profile', report_name)
+ outfile = (outfile + '.html') unless outfile.end_with? '.html'
+ FileUtils.mkdir_p(File.dirname(outfile))
+ File.open(outfile, 'w') do |f|
+ printer.print(f, min_percent: 1)
+ end
+ end
+end
+
###
# Page options, layouts, aliases and proxies
###
Unfortunately, generating this in the default mode (which implies --parallel
) wasn't very illuminating:
(On the shared runners used by this site, we have 2 CPUs, according to https://gitlab.slack.com/archives/C0SFP840G/p1545226526151000?thread_ts=1545226152.150800&cid=C0SFP840G. This does imply that a beefier machine might lead to improvements.)
Here's a profile for NO_CONTRACTS=true MIDDLEMAN_ENV=production bundle exec middleman build --profile --parallel false
: build.html
One observation is that we spend a surprising (to me) amount of time in generating breadcrumbs.
We also spend a decent amount of time in Haml - although how much of that is Haml itself and how much is our templates, I don't know. I didn't see any instructions for Hamlit + Middleman, and the naive 8aeb77a4 still uses Haml
Another thing I'd like from Middleman is to tell me which paths take the most time to render.