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

Rewrite Kernel#tap with Ruby #3281

Merged
merged 2 commits into from Jul 3, 2020
Merged

Rewrite Kernel#tap with Ruby #3281

merged 2 commits into from Jul 3, 2020

Conversation

@k0kubun
Copy link
Member

k0kubun commented Jul 3, 2020

because Ruby is faster than C.

$ benchmark-driver -v --rbenv 'before;after' benchmark/kernel_tap.yml benchmark/vm_symbol_block_pass.rb --repeat-count=4
before: ruby 2.8.0dev (2020-07-03T06:16:55Z master 01776ca) [x86_64-linux]
after: ruby 2.8.0dev (2020-07-03T07:14:40Z builtin-tap be549c7) [x86_64-linux]
Calculating -------------------------------------
                         before       after
          kernel_tap    22.130M     29.958M i/s -     20.000M times in 0.903731s 0.667597s
vm_symbol_block_pass      1.439       1.485 i/s -       1.000 times in 0.694709s 0.673524s

Comparison:
                       kernel_tap
               after:  29958213.1 i/s
              before:  22130488.0 i/s - 1.35x  slower

             vm_symbol_block_pass
               after:         1.5 i/s
              before:         1.4 i/s - 1.03x  slower
@shyouhei
Copy link
Member

shyouhei commented Jul 3, 2020

Second thought you might also want to do this for Kernel#then.

@benoittgt
Copy link
Contributor

benoittgt commented Jul 3, 2020

Related explanation submitted by @k0kubun on twitter:

I thought a block must be inlinable over methods which are currently written in C with future JIT, but it's actually hard to update (for inlining block) a part of C code from JIT. My current plan is to mix C and Ruby for methods like #each, but then I noticed #tap was too easy :)

😊

@k0kubun
Copy link
Member Author

k0kubun commented Jul 3, 2020

Second thought you might also want to do this for Kernel#then.

Absolutely 🙂 I'll prepare another PR to see CI results for it separately though.

@k0kubun k0kubun merged commit f3a0d7a into ruby:master Jul 3, 2020
100 checks passed
100 checks passed
CodeQL-Build CodeQL-Build
Details
gcc-10
Details
make (check, --jit)
Details
make (check)
Details
check_branch
Details
make (check, ubuntu-20.04)
Details
make (test, windows-2019, 2019)
Details
make (check)
Details
gcc-9
Details
make (check, --jit-wait)
Details
make (check, ubuntu-20.04, -DRUBY_DEBUG)
Details
make (test-bundler-parallel)
Details
gcc-8
Details
make (check, ubuntu-18.04)
Details
make (test-bundled-gems)
Details
gcc-7
Details
make (check, ubuntu-18.04, -DRUBY_DEBUG)
Details
make (leaked-globals)
Details
gcc-6
Details
make (check, ubuntu-16.04)
Details
gcc-5
Details
make (test-bundler-parallel, ubuntu-20.04)
Details
gcc-4.8
Details
make (test-bundler-parallel, ubuntu-20.04, -DRUBY_DEBUG)
Details
clang-11
Details
make (test-bundler-parallel, ubuntu-18.04)
Details
clang-10
Details
make (test-bundler-parallel, ubuntu-18.04, -DRUBY_DEBUG)
Details
clang-9
Details
make (test-bundled-gems, ubuntu-20.04)
Details
clang-8
Details
make (test-bundled-gems, ubuntu-20.04, -DRUBY_DEBUG)
Details
clang-7
Details
make (test-bundled-gems, ubuntu-18.04)
Details
clang-6.0
Details
make (test-bundled-gems, ubuntu-18.04, -DRUBY_DEBUG)
Details
clang-5.0
Details
make (test-all TESTS=--repeat-count=2, ubuntu-20.04)
Details
clang-4.0
Details
make (test-all TESTS=--repeat-count=2, ubuntu-18.04)
Details
clang-3.9
Details
make (leaked-globals, ubuntu-20.04)
Details
c99
Details
make (leaked-globals, ubuntu-18.04)
Details
c11
Details
c17
Details
c2x
Details
c++98
Details
c++11
Details
c++14
Details
c++17
Details
c++2a
Details
-O0
Details
-O3
Details
gmp
Details
jemalloc
Details
valgrind
Details
coroutine=ucontext
Details
coroutine=copy
Details
disable-mathn
Details
disable-jit-support
Details
disable-dln
Details
disable-rubygems
Details
OPT_THREADED_CODE=1
Details
OPT_THREADED_CODE=2
Details
OPT_THREADED_CODE=3
Details
NDEBUG
Details
RUBY_DEBUG
Details
ARRAY_DEBUG
Details
BIGNUM_DEBUG
Details
CCAN_LIST_DEBUG
Details
CPDEBUG=-1
Details
ENC_DEBUG
Details
GC_DEBUG
Details
HASH_DEBUG
Details
ID_TABLE_DEBUG
Details
RGENGC_DEBUG=-1
Details
SYMBOL_DEBUG
Details
THREAD_DEBUG=-1
Details
RGENGC_CHECK_MODE
Details
TRANSIENT_HEAP_CHECK_MODE
Details
VM_CHECK_MODE
Details
USE_EMBED_CI=0
Details
USE_FLONUM=0
Details
USE_LAZY_LOAD
Details
USE_RINCGC=0
Details
USE_SYMBOL_GC=0
Details
USE_THREAD_CACHE=0
Details
USE_TRANSIENT_HEAP=0
Details
USE_RUBY_DEBUG_LOG=1
Details
DEBUG_FIND_TIME_NUMGESS
Details
DEBUG_INTEGER_PACK
Details
ENABLE_PATH_CHECK
Details
GC_DEBUG_STRESS_TO_CLASS
Details
GC_ENABLE_LAZY_SWEEP=0
Details
GC_PROFILE_DETAIL_MEMOTY
Details
GC_PROFILE_MORE_DETAIL
Details
CALC_EXACT_MALLOC_SIZE
Details
MALLOC_ALLOCATED_SIZE_CHECK
Details
IBF_ISEQ_ENABLE_LOCAL_BUFFER
Details
@k0kubun k0kubun deleted the k0kubun:builtin-tap branch Jul 3, 2020
@ruurd
Copy link

ruurd commented Jul 10, 2020

because Ruby is faster than C.

Lies. Damned lies. Statistics. Did you find out WHY it is faster?

@simi
Copy link
Contributor

simi commented Jul 10, 2020

Lies. Damned lies. Statistics. Did you find out WHY it is faster?

It is not meant it is faster in general, but in this case of Kernel#tap implementation. Stats are in original post.

@ruurd
Copy link

ruurd commented Jul 10, 2020

WHY is it faster. That is the question. Concluding that Ruby is faster here is uninteresting. Do a root cause analysis. Then we learn something perhaps.

@simi
Copy link
Contributor

simi commented Jul 10, 2020

Everything is written in this thread actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.