Run liquidtruffle from the performance runner

This commit is contained in:
Justin Li
2019-08-23 16:11:00 -04:00
parent 49488e3757
commit 350addf364
4 changed files with 25 additions and 7 deletions

10
Gemfile
View File

@@ -9,9 +9,9 @@ group :benchmark, :test do
gem 'benchmark-ips'
gem 'memory_profiler'
install_if -> { RUBY_PLATFORM !~ /mingw|mswin|java/ } do
gem 'stackprof'
end
# install_if -> { RUBY_PLATFORM !~ /mingw|mswin|java/ } do
# gem 'stackprof'
# end
end
group :test do
@@ -21,3 +21,7 @@ group :test do
gem 'liquid-c', github: 'Shopify/liquid-c', ref: '9168659de45d6d576fce30c735f857e597fa26f6'
end
end
# gem "byebug", "~> 11.0"
gem "pry", "~> 0.12.2"

View File

@@ -1,3 +1,4 @@
require 'liquid/ast_to_portable_json'
module Liquid
# Templates are central to liquid.
# Interpretating templates is a two step process. First you compile the
@@ -130,6 +131,8 @@ module Liquid
@line_numbers = options[:line_numbers] || @profiling
parse_context = options.is_a?(ParseContext) ? options : ParseContext.new(options)
@root = Document.parse(tokenize(source), parse_context)
@json = ASTToPortableJSON.dump(self)
@warnings = parse_context.warnings
self
end
@@ -198,6 +201,15 @@ module Liquid
context.add_filters(args.pop)
end
unless @truffle_context
environment = context.environments.first
@truffle_context = Polyglot.eval('liquid', @json)
environment.each do |key, value|
@truffle_context[key] = value
end
end
return @truffle_context[:render].call
# Retrying a render resets resource usage
context.resource_limits.reset

View File

@@ -1,3 +1,4 @@
require 'bundler/setup'
require 'benchmark/ips'
require_relative 'theme_runner'
@@ -5,14 +6,15 @@ Liquid::Template.error_mode = ARGV.first.to_sym if ARGV.first
profiler = ThemeRunner.new
Benchmark.ips do |x|
x.time = 10
x.warmup = 5
x.time = 60
x.warmup = 1
puts
puts "Running benchmark for #{x.time} seconds (with #{x.warmup} seconds warmup)."
puts
x.report("parse:") { profiler.compile }
profiler.compile
# x.report("parse:") { profiler.compile }
x.report("render:") { profiler.render }
x.report("parse & render:") { profiler.run }
end

View File

@@ -24,7 +24,7 @@ class ThemeRunner
# Initialize a new liquid ThemeRunner instance
# Will load all templates into memory, do this now so that we don't profile IO.
def initialize
@tests = Dir[__dir__ + '/tests/**/*.liquid'].collect do |test|
@tests = Dir[__dir__ + '/tests/ripen/product.liquid'].collect do |test|
next if File.basename(test) == 'theme.liquid'
theme_path = File.dirname(test) + '/theme.liquid'