From 350addf36461d930bb18a4e22e2e30f190247c57 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Fri, 23 Aug 2019 16:11:00 -0400 Subject: [PATCH] Run liquidtruffle from the performance runner --- Gemfile | 10 +++++++--- lib/liquid/template.rb | 12 ++++++++++++ performance/benchmark.rb | 8 +++++--- performance/theme_runner.rb | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 37ffe1d..68d7c91 100644 --- a/Gemfile +++ b/Gemfile @@ -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" diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index 31a67e4..1cef639 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -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 diff --git a/performance/benchmark.rb b/performance/benchmark.rb index 68c568c..7c4477b 100644 --- a/performance/benchmark.rb +++ b/performance/benchmark.rb @@ -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 diff --git a/performance/theme_runner.rb b/performance/theme_runner.rb index 9f6a1fc..5032af6 100644 --- a/performance/theme_runner.rb +++ b/performance/theme_runner.rb @@ -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'