truffleruby
truffleruby copied to clipboard
A simple benchmark-ips script starts the finaliser thread and object sharing
<internal:core> core/truffle/ffi/pointer.rb:255:in `autorelease='
<internal:core> core/truffle/ffi/pointer.rb:255:in `new'
<internal:core> core/truffle/ffi/pointer.rb:262:in `from_string'
<internal:core> core/posix.rb:330:in `block (2 levels) in with_array_of_strings_pointer'
<internal:core> core/posix.rb:329:in `map'
<internal:core> core/posix.rb:329:in `block in with_array_of_strings_pointer'
<internal:core> core/truffle/ffi/pointer.rb:250:in `new'
<internal:core> core/posix.rb:328:in `with_array_of_strings_pointer'
<internal:core> core/truffle/process_operations.rb:488:in `block in posix_spawnp'
<internal:core> core/posix.rb:322:in `block in with_array_of_ints'
<internal:core> core/truffle/ffi/pointer.rb:250:in `new'
<internal:core> core/posix.rb:320:in `with_array_of_ints'
<internal:core> core/truffle/process_operations.rb:487:in `posix_spawnp'
<internal:core> core/truffle/process_operations.rb:418:in `spawn'
<internal:core> core/truffle/process_operations.rb:84:in `spawn'
<internal:core> core/io.rb:862:in `popen'
<internal:core> core/kernel.rb:178:in ``'
/Users/chrisseaton/src/github.com/Shopify/truffleruby/mxbuild/truffleruby-jvm/languages/ruby/lib/truffle/truffle/openssl-prefix.rb:14:in `<top (required)>'
<internal:core> core/kernel.rb:260:in `require'
/Users/chrisseaton/src/github.com/Shopify/truffleruby/mxbuild/truffleruby-jvm/languages/ruby/lib/truffle/rbconfig.rb:99:in `<module:RbConfig>'
/Users/chrisseaton/src/github.com/Shopify/truffleruby/mxbuild/truffleruby-jvm/languages/ruby/lib/truffle/rbconfig.rb:37:in `<top (required)>'
<internal:core> core/kernel.rb:260:in `require'
/Users/chrisseaton/src/github.com/Shopify/truffleruby/mxbuild/truffleruby-jvm/languages/ruby/lib/mri/rubygems.rb:9:in `<top (required)>'
<internal:core> core/kernel.rb:260:in `require'
/Users/chrisseaton/src/github.com/Shopify/truffleruby/mxbuild/truffleruby-jvm/languages/ruby/lib/patches/rubygems.rb:6:in `<top (required)>'
<internal:core> core/kernel.rb:234:in `gem_original_require'
<internal:core> core/kernel.rb:264:in `require'
/Users/chrisseaton/xxxx/class-variables/benchmarks.rb:1:in `<main>'
We should possibly:
- check if this makes sense in the first place - why is RubyGems doing this?
- not use the Ruby finaliser thread for something that can be handled outside of a context
Right, that explains why it only happens on macOS then, it's due to the subprocesses of https://github.com/oracle/truffleruby/blob/634c0ae2517d04261b05e357b79da009eeac62ff/lib/truffle/truffle/openssl-prefix.rb. I'll look into it (running an extra subcommand when loading RubyGems to find libssl also seems suboptimal).
https://github.com/oracle/truffleruby/commit/8ca9852433bb4974bdf4e7306feee7e06235faec avoids creating autorelease pointers for spawning subprocesses.
It would be interesting to know how long brew --prefix takes to see if it's worth optimizing for the common case of Homebrew being in /usr/local.
@chrisseaton Could you measure that?
Regarding having Pointer finalizers without an extra thread, that's something that probably makes more sense in Truffle, and NFI has a NativeAllocation that does something very similar.
With the new Truffle safepoints it might also be possible to simply run all finalizers on the main Ruby thread, but I'm unsure if it's a good idea or not.
Almost a second!
chrisseaton@Chris-Seatons-MacBook-Pro graal % disable -r time
chrisseaton@Chris-Seatons-MacBook-Pro graal % time -p brew --prefix openssl
/usr/local/opt/[email protected]
real 0.89
user 0.48
sys 0.40
chrisseaton@Chris-Seatons-MacBook-Pro graal % time -p brew --prefix openssl
/usr/local/opt/[email protected]
real 0.86
user 0.47
sys 0.38
chrisseaton@Chris-Seatons-MacBook-Pro graal % time -p brew --prefix openssl
/usr/local/opt/[email protected]
real 0.85
user 0.47
sys 0.37
chrisseaton@Chris-Seatons-MacBook-Pro ~ % time -p brew --prefix
/usr/local
real 0.02
user 0.01
sys 0.01
chrisseaton@Chris-Seatons-MacBook-Pro ~ % time -p brew --prefix
/usr/local
real 0.02
user 0.01
sys 0.01
chrisseaton@Chris-Seatons-MacBook-Pro ~ % time -p brew --prefix
/usr/local
real 0.03
user 0.01
sys 0.01
Right, so that's more like 20-30ms, seems worth optimizing the common case.
https://github.com/oracle/truffleruby/commit/3b05154d2bc1344eb161514388d8d8917b847c3e avoids that extra subprocess if Homebrew is in /usr/local.