Skip to content

Commit

Permalink
Compare and report binary size changes in PRs (realm#5934)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny authored Jan 3, 2025
1 parent 4e5911b commit 28ce97c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tools/oss-check
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,25 @@ def print_rules_changed
end
end

def report_binary_size
size_branch = File.size("#{@working_dir}/builds/swiftlint-branch")
size_main = File.size("#{@working_dir}/builds/swiftlint-main")
if size_branch == size_main
message "Building this branch resulted in the same binary size as when built on `main`."
else
percent_change = 100 * (size_branch - size_main) / size_main
faster_slower = size_branch < size_main ? 'smaller' : 'larger'
in_kilo_bytes = ->(size) { (size / 1024.0).round(2) }
msg = "Building this branch resulted in a binary size of #{in_kilo_bytes.call(size_branch)} KiB " \
"vs #{in_kilo_bytes.call(size_main)} KiB when built on `main` (#{percent_change.to_i}\% #{faster_slower})."
if percent_change.abs < 2
message msg
else
warn msg
end
end
end

################################
# Script
################################
Expand Down Expand Up @@ -329,6 +348,9 @@ make_directory_structure
build(branch)
end

# Compare binary size of both builds.
report_binary_size

unless @options[:force]
full_version_branch = `#{@working_dir}/builds/swiftlint-branch version --verbose`
full_version_main = `#{@working_dir}/builds/swiftlint-main version --verbose`
Expand Down

0 comments on commit 28ce97c

Please sign in to comment.