Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YJIT: add top C function call counts to --yjit-stats #9047

Merged
merged 5 commits into from
Nov 27, 2023

Conversation

maximecb
Copy link
Contributor

My little pet project. Add top (uninlined) C function calls to --yjit-stats. This can reveal some easy optimization targets without needing to use a profiler.

Lobsters:

Top-20 most frequent C calls (31.3% of C calls):
                        Hash#fetch:    770,426 ( 9.4%)
                         Class#new:    366,541 ( 4.5%)
                        Array#each:    232,277 ( 2.8%)
                  Class#superclass:    160,770 ( 2.0%)
                        Array#any?:    117,291 ( 1.4%)
    Concurrent::Array#reverse_each:     97,111 ( 1.2%)
                     Regexp#match?:     78,375 ( 1.0%)
                         Hash#key?:     66,934 ( 0.8%)
                        Class#name:     66,534 ( 0.8%)
          SQLite3::Statement#done?:     61,089 ( 0.7%)
           SQLite3::Statement#step:     61,089 ( 0.7%)
                       Hash#empty?:     58,755 ( 0.7%)
                       Symbol#to_s:     57,037 ( 0.7%)
                     TrueClass#===:     56,353 ( 0.7%)
                         Object#!=:     56,066 ( 0.7%)
                      Array#reject:     55,639 ( 0.7%)
                    FalseClass#===:     54,948 ( 0.7%)
                          Hash#dup:     52,600 ( 0.6%)
                         Array#map:     52,183 ( 0.6%)
                    Array#include?:     45,110 ( 0.6%)

Here Class#superclass may be an easy optimization target, TrueClass#===, Hash#empty? and Class#name as well. Also surprised that we are still calling Symbol#to_s.

Optcarrot:

Top-20 most frequent C calls (20.5% of C calls):
             Integer#*:  2,643,814 ( 8.2%)
             Array#[]=:  1,540,322 ( 4.8%)
         Array#rotate!:  1,493,457 ( 4.6%)
            Integer#>>:    673,674 ( 2.1%)
            Array#size:    143,732 ( 0.4%)
             Integer#^:    109,241 ( 0.3%)
             Method#[]:     28,777 ( 0.1%)
          Fiber#resume:      5,443 ( 0.0%)
           Class#yield:      5,443 ( 0.0%)
            Array#each:      2,732 ( 0.0%)
     Integer#object_id:      2,029 ( 0.0%)
           Float#floor:      1,449 ( 0.0%)
       Array#object_id:      1,014 ( 0.0%)
           Array#uniq!:        995 ( 0.0%)
           Symbol#to_s:        612 ( 0.0%)
           Array#clear:        513 ( 0.0%)
    Symbol#start_with?:        397 ( 0.0%)
        Array#include?:        180 ( 0.0%)
               Float#/:        171 ( 0.0%)
               Float#-:        171 ( 0.0%)

On optcarrot, we already inline almost 80% of C function calls, which is very impressive and probably explains why we're so fast on that benchmark. The remaining top C functions still show many potential optimization targets, however. There is room to be even faster eventually.

@maximecb maximecb self-assigned this Nov 27, 2023
@matzbot matzbot requested a review from a team November 27, 2023 21:17
yjit/src/codegen.rs Outdated Show resolved Hide resolved
yjit/src/codegen.rs Outdated Show resolved Hide resolved
Copy link
Member

@k0kubun k0kubun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems very useful 👍

@maximecb maximecb enabled auto-merge (squash) November 27, 2023 22:32
@maximecb maximecb merged commit 7f50c70 into ruby:master Nov 27, 2023
97 of 98 checks passed
@maximecb maximecb deleted the yjit_cfunc_counts branch November 27, 2023 22:49
@casperisfine
Copy link
Contributor

Class#new: 366,541 ( 4.5%)

😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants