Skip to content

Commit 267fefb

Browse files
Add a static benchmark for xcmetrics (#3063)
1 parent f8690e3 commit 267fefb

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

.github/workflows/xcmetrics.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Run Performance Metrics
4343
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
4444
run: bundle exec fastlane xcmetrics
45-
timeout-minutes: 60
45+
timeout-minutes: 120
4646
env:
4747
GITHUB_PR_NUM: ${{ github.event.pull_request.number }}
4848
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}

fastlane/Fastfile

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -388,40 +388,40 @@ lane :xcmetrics do |options|
388388

389389
sh("git clone [email protected]:GetStream/stream-swift-performance-benchmarks.git #{File.dirname(performance_path)}")
390390
branch_performance = xcmetrics_log_parser(log: xcodebuild_output)
391-
previous_release_branch = "release/#{last_git_tag}"
392391
performance_benchmarks = JSON.parse(File.read(performance_path))
393-
previous_release_performance = performance_benchmarks[previous_release_branch]
392+
expected_performance = performance_benchmarks['benchmark']
394393

395-
markdown_table = "## StreamChat XCMetrics\n| `target` | `metric` | `#{previous_release_branch}` | `branch` | `performance` | `status` |\n| - | - | - | - | - | - |\n"
394+
markdown_table = "## StreamChat XCMetrics\n| `target` | `metric` | `benchmark` | `branch` | `performance` | `status` |\n| - | - | - | - | - | - |\n"
396395
['testMessageListScrollTime', 'testChannelListScrollTime'].each do |test_name|
397396
index = 0
398397
['hitches_total_duration', 'duration', 'hitch_time_ratio', 'frame_rate', 'number_of_hitches'].each do |metric|
399-
release_value = previous_release_performance[test_name][metric]['value']
398+
benchmark_value = expected_performance[test_name][metric]['value']
400399
branch_value = branch_performance[test_name][metric]['value']
401400
value_extension = branch_performance[test_name][metric]['ext']
402401

403402
max_stddev = 0.1 # Default Xcode Max STDDEV is 10%
404403
status_emoji =
405-
if branch_value > release_value && branch_value < release_value + (release_value * max_stddev)
406-
'🟡' # Warning if a branch is 10% less performant than the previous release
407-
elsif branch_value > release_value
408-
'🔴' # Failure if a branch is more than 10% less performant than the previous release
404+
if branch_value > benchmark_value && branch_value < benchmark_value + (benchmark_value * max_stddev)
405+
'🟡' # Warning if a branch is 10% less performant than the benchmark
406+
elsif branch_value > benchmark_value
407+
'🔴' # Failure if a branch is more than 10% less performant than the benchmark
409408
else
410-
'🟢' # Success if a branch is more performant or equals to the previous release
409+
'🟢' # Success if a branch is more performant or equals to the benchmark
411410
end
412411

413-
diff = ((release_value - branch_value) * 100 / release_value.to_f).to_f.round(1)
412+
benchmark_value_avoids_zero_division = benchmark_value == 0 ? 1 : benchmark_value
413+
diff = ((benchmark_value - branch_value) * 100.0 / benchmark_value_avoids_zero_division).round(2)
414414
diff_emoji = diff > 0 ? '🔼' : '🔽'
415415

416416
title = metric.to_s.gsub('_', ' ').capitalize
417417
target = index.zero? ? test_name.match(/(?<=test)(.*?)(?=ScrollTime)/).to_s : ''
418418
index += 1
419419

420-
markdown_table << "| #{target} | #{title} | #{release_value} #{value_extension} | #{branch_value} #{value_extension} | #{diff}% #{diff_emoji} | #{status_emoji} |\n"
420+
markdown_table << "| #{target} | #{title} | #{benchmark_value} #{value_extension} | #{branch_value} #{value_extension} | #{diff}% #{diff_emoji} | #{status_emoji} |\n"
421421
FastlaneCore::PrintTable.print_values(
422422
title: "⏳ #{title} ⏳",
423423
config: {
424-
"#{previous_release_branch}": "#{release_value} #{value_extension}",
424+
benchmark: "#{benchmark_value} #{value_extension}",
425425
branch: "#{branch_value} #{value_extension}",
426426
diff: "#{diff}% #{diff_emoji}",
427427
status: status_emoji
@@ -432,8 +432,8 @@ lane :xcmetrics do |options|
432432

433433
UI.user_error!("See Firebase error above ☝️") unless firebase_error.to_s.empty?
434434

435-
if is_ci && ENV.key?('GITHUB_PR_NUM')
436-
pr_comment_required = true
435+
if is_ci
436+
pr_comment_required = ENV.key?('GITHUB_PR_NUM')
437437
performance_benchmarks[current_branch] = branch_performance
438438
UI.message("Performance benchmarks: #{performance_benchmarks}")
439439
File.write(performance_path, JSON.pretty_generate(performance_benchmarks))
@@ -469,23 +469,23 @@ private_lane :xcmetrics_log_parser do |options|
469469

470470
metrics[test_name] = {
471471
'hitches_total_duration' => {
472-
'value' => hitches_total_duration ? hitches_total_duration[1].to_f.round(1) : '?',
472+
'value' => hitches_total_duration ? hitches_total_duration[1].to_f.round(2) : '?',
473473
'ext' => 'ms'
474474
},
475475
'duration' => {
476-
'value' => duration ? duration[1].to_f.round(1) : '?',
476+
'value' => duration ? duration[1].to_f.round(2) : '?',
477477
'ext' => 's'
478478
},
479479
'hitch_time_ratio' => {
480-
'value' => hitch_time_ratio ? hitch_time_ratio[1].to_f.round(1) : '?',
480+
'value' => hitch_time_ratio ? hitch_time_ratio[1].to_f.round(2) : '?',
481481
'ext' => 'ms per s'
482482
},
483483
'frame_rate' => {
484-
'value' => frame_rate ? frame_rate[1].to_f.round(1) : '?',
484+
'value' => frame_rate ? frame_rate[1].to_f.round(2) : '?',
485485
'ext' => 'fps'
486486
},
487487
'number_of_hitches' => {
488-
'value' => number_of_hitches ? number_of_hitches[1].to_i : '?',
488+
'value' => number_of_hitches ? number_of_hitches[1].to_f.round(2) : '?',
489489
'ext' => ''
490490
}
491491
}
@@ -781,7 +781,20 @@ private_lane :create_pr do |options|
781781
end
782782

783783
private_lane :current_branch do
784-
ENV['BRANCH_NAME'].to_s.empty? ? git_branch : ENV.fetch('BRANCH_NAME')
784+
github_pr_branch_name = ENV['BRANCH_NAME'].to_s
785+
github_ref_branch_name = ENV['GITHUB_REF'].to_s.sub('refs/heads/', '')
786+
fastlane_branch_name = git_branch
787+
788+
branch_name = if !github_pr_branch_name.empty?
789+
github_pr_branch_name
790+
elsif !fastlane_branch_name.empty?
791+
fastlane_branch_name
792+
elsif !github_ref_branch_name.empty?
793+
github_ref_branch_name
794+
end
795+
796+
UI.important("Current branch: #{branch_name} 🕊️")
797+
branch_name
785798
end
786799

787800
private_lane :git_status do |options|

0 commit comments

Comments
 (0)