summaryrefslogtreecommitdiff
path: root/yjit.rb
diff options
context:
space:
mode:
authorMau Magnaguagno <maumagnaguagno@gmail.com>2023-03-17 11:29:42 -0300
committerGitHub <noreply@github.com>2023-03-17 10:29:42 -0400
commit11f299fab749bd2e0c5e49ca4db8c9c84b8e5970 (patch)
tree676ca58a072d972a1eae051baf2a37d8d513b589 /yjit.rb
parentc65d7b4bea170ffe4811534ab33b231f7f57d69f (diff)
downloadruby-11f299fab749bd2e0c5e49ca4db8c9c84b8e5970.tar.gz
YJIT: skip intermediate arrays in print_sorted_exit_counts (#7547)
Early total_exits condition. Replace Array#sort_by/first(how_many) with Array#max_by(how_many). Replace Array#map/max with Array#max_by, match print_counters style for longest_name_length.
Diffstat (limited to 'yjit.rb')
-rw-r--r--yjit.rb19
1 files changed, 10 insertions, 9 deletions
diff --git a/yjit.rb b/yjit.rb
index 807541e0a5..7d56bf0517 100644
--- a/yjit.rb
+++ b/yjit.rb
@@ -308,23 +308,24 @@ module RubyVM::YJIT
end
def print_sorted_exit_counts(stats, prefix:, how_many: 20, left_pad: 4) # :nodoc:
- exits = []
- stats.each do |k, v|
- if k.start_with?(prefix)
- exits.push [k.to_s.delete_prefix(prefix), v]
- end
- end
-
- exits = exits.select { |_name, count| count > 0 }.sort_by { |_name, count| -count }.first(how_many)
total_exits = total_exit_count(stats)
if total_exits > 0
+ exits = []
+ stats.each do |k, v|
+ if k.start_with?(prefix)
+ exits.push [k.to_s.delete_prefix(prefix), v]
+ end
+ end
+
+ exits = exits.select { |_name, count| count > 0 }.max_by(how_many) { |_name, count| count }
+
top_n_total = exits.sum { |name, count| count }
top_n_exit_pct = 100.0 * top_n_total / total_exits
$stderr.puts "Top-#{exits.size} most frequent exit ops (#{"%.1f" % top_n_exit_pct}% of exits):"
- longest_insn_name_len = exits.map { |name, count| name.length }.max
+ longest_insn_name_len = exits.max_by { |name, count| name.length }.first.length
exits.each do |name, count|
padding = longest_insn_name_len + left_pad
padded_name = "%#{padding}s" % name