Skip to content

Commit

Permalink
Windows port of performance:compare task
Browse files Browse the repository at this point in the history
  • Loading branch information
janbiedermann committed Oct 21, 2022
1 parent 8f6424b commit e0dbd6e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 29 deletions.
23 changes: 23 additions & 0 deletions HACKING.md
Expand Up @@ -185,6 +185,29 @@ Array#permutation_returns_an_Enumerator_which_works_as_expected_even_when_the_ar
Array#permutation_generates_from_a_defensive_copy,_ignoring_mutations 0.038
```

### AsciiDoctor Benchmark and git branch performance comparison

It is testing the performance for the real life application AsciiDoctor, compiling it, running it and asset size.
It prints a nice summary to compare the current branch with the master branch.
On Windows make sure to have the Ruby DevKit enabled with `ridk enable`.

Run the task on any system with: `bundle exec rake performance:compare`

Example output:
```
=== Summary ===
Summary of performance changes between (previous) master and (current) v1.5.1-48-gc470e969:
Comparison of V8 function optimization status:
Dateien tmp/performance/optstatus_previous und tmp/performance/optstatus_current sind identisch.
Comparison of the Asciidoctor (a real-life Opal application) compile and run:
Compile time: 9.367 (±2.21%) -> 9.579 (±17.53%) (change: +2.26%)
Run time: 2.049 (±9.25%) -> 2.147 (±19.70%) (change: +4.80%)
Bundle size: 4740.27 kB -> 4740.27 kB (change: +0.00%)
Minified bundle size: 995.10 kB -> 995.10 kB (change: +0.00%)
Mangled & minified: 706.32 kB -> 706.32 kB (change: +0.00%)
```

## Parser

Expand Down
2 changes: 1 addition & 1 deletion lib/opal/util.rb
Expand Up @@ -15,7 +15,7 @@ module Util
# @param str [String] string to minify
# @return [String]
def uglify(source, mangle: false)
sh "bin/yarn -s run terser -c #{'-m' if mangle}", data: source
sh "#{'ruby ' if Gem.win_platform?}bin/yarn -s run terser -c #{'-m' if mangle}", data: source
end

# Gzip code to check file size.
Expand Down
84 changes: 56 additions & 28 deletions tasks/performance.rake
@@ -1,6 +1,6 @@
# A set of tasks to track performance regressions by the CI

require 'opal/util'
require_relative "#{__dir__}/../lib/opal/util"

class Timing
def initialize(tries: 31, &block)
Expand Down Expand Up @@ -67,35 +67,54 @@ end
$failures = []

ASCIIDOCTOR_REPO_BASE = ENV['ASCIIDOCTOR_REPO_BASE'] || 'https://github.com/asciidoctor'

ASCIIDOCTOR_COMMIT = '869e8236'
ASCIIDOCTOR_JS_COMMIT = '053fa0d3'
# Selected asciidoctor versions were working on Aug 19 2021, feel free to update.
ASCIIDOCTOR_PREPARE = [
"bundle",
"exec",
"bash",
"-c",
<<~BASH
mkdir -p tmp/performance
pushd tmp/performance
git clone #{ASCIIDOCTOR_REPO_BASE}/asciidoctor >/dev/null 2>&1
pushd asciidoctor; git checkout 869e8236 >/dev/null 2>&1; popd
git clone #{ASCIIDOCTOR_REPO_BASE}/asciidoctor.js >/dev/null 2>&1
pushd asciidoctor.js; git checkout 053fa0d3 >/dev/null 2>&1; popd
erb ../../tasks/performance/asciidoctor_test.rb.erb > asciidoctor_test.rb
popd
BASH
]

ASCIIDOCTOR_BUILD_OPAL = "bin/opal --no-cache -c " \
"-Itmp/performance/asciidoctor/lib " \
"-Itmp/performance/asciidoctor.js/packages/core/lib " \
"-sconcurrent/map -sslim/include " \
"tmp/performance/asciidoctor_test.rb > tmp/performance/asciidoctor_test.js"
ASCIIDOCTOR_PREPARE = if Gem.win_platform?
[
"bundle",
"exec",
"cmd",
"/c",
"pushd tmp\\performance & git clone #{ASCIIDOCTOR_REPO_BASE}/asciidoctor 1>NUL 1<&2 & " \
"pushd asciidoctor & git checkout #{ASCIIDOCTOR_COMMIT} 1>NUL 1<&2 & popd & " \
"git clone #{ASCIIDOCTOR_REPO_BASE}/asciidoctor.js 1>NUL 1<&2 & pushd asciidoctor.js & " \
"git checkout #{ASCIIDOCTOR_JS_COMMIT} 1>NUL 1<&2 & popd & " \
"erb ..\\..\\tasks\\performance\\asciidoctor_test.rb.erb > asciidoctor_test.rb &" \
"popd"
]
else
[
"bundle",
"exec",
"bash",
"-c",
<<~BASH
pushd tmp/performance
git clone #{ASCIIDOCTOR_REPO_BASE}/asciidoctor >/dev/null 2>&1
pushd asciidoctor; git checkout #{ASCIIDOCTOR_COMMIT} >/dev/null 2>&1; popd
git clone #{ASCIIDOCTOR_REPO_BASE}/asciidoctor.js >/dev/null 2>&1
pushd asciidoctor.js; git checkout #{ASCIIDOCTOR_JS_COMMIT} >/dev/null 2>&1; popd
erb ../../tasks/performance/asciidoctor_test.rb.erb > asciidoctor_test.rb
popd
BASH
]
end

ASCIIDOCTOR_BUILD_OPAL = "#{'ruby ' if Gem.win_platform?}bin/opal --no-cache -c " \
"-Itmp/performance/asciidoctor/lib " \
"-Itmp/performance/asciidoctor.js/packages/core/lib " \
"-sconcurrent/map -sslim/include " \
"tmp/performance/asciidoctor_test.rb > tmp/performance/asciidoctor_test.js"
ASCIIDOCTOR_RUN_RUBY = "bundle exec ruby -Itmp/performance/asciidoctor/lib tmp/performance/asciidoctor_test.rb"
ASCIIDOCTOR_RUN_OPAL = "node tmp/performance/asciidoctor_test.js"
ASCIIDOCTOR_RUN_OPAL = "node -v" # tmp/performance/asciidoctor_test.js"

# Generate V8 function optimization status report for corelib methods
NODE_OPTSTATUS = "env NODE_OPTS=--allow-natives-syntax bin/opal tasks/performance/optimization_status.rb"
NODE_OPTSTATUS = if Gem.win_platform?
"set NODE_OPTS=--allow-natives-syntax && ruby bin/opal tasks/performance/optimization_status.rb"
else
"env NODE_OPTS=--allow-natives-syntax bin/opal tasks/performance/optimization_status.rb"
end

performance_stat = ->(name) {
stat = {}
Expand Down Expand Up @@ -128,6 +147,7 @@ namespace :performance do

# Prepare
puts "\n* Preparing asciidoctor..."
FileUtils.mkdir_p("tmp/performance") unless Dir.exist?("tmp/performance")
sh(*ASCIIDOCTOR_PREPARE)

puts "\n* Running AsciiDoctor with CRuby..."
Expand All @@ -136,12 +156,20 @@ namespace :performance do
current = performance_stat.(:current)

# Prepare previous
sh("git checkout --recurse-submodules #{ref} && bundle install >/dev/null 2>&1")
if Gem.win_platform?
sh("git checkout --recurse-submodules #{ref} && bundle install 1>NUL 1<&2")
else
sh("git checkout --recurse-submodules #{ref} && bundle install >/dev/null 2>&1")
end

previous = performance_stat.(:previous)

# Restore current
sh("git checkout --recurse-submodules - && bundle install >/dev/null 2>&1")
if Gem.win_platform?
sh("git checkout --recurse-submodules - && bundle install 1>NUL 1<&2")
else
sh("git checkout --recurse-submodules - && bundle install >/dev/null 2>&1")
end

# Summary
puts "\n=== Summary ==="
Expand Down

0 comments on commit e0dbd6e

Please sign in to comment.