* The stdlib StringIO is synchronized and this occurs a high overhead.
* This is about twice as fast on TruffleRuby but surprisingly it is slower on JRuby.
I am not sure why but probably @ivar access and integer arithmetic
is much slower than Java field access/arithmetic on JRuby.
* On CRuby interpreter it is slower, which is expected as the GVL already protects StringIO.
* So we enable this only on TruffleRuby to not slow down other Rubies.
* PRISM_FFI_BACKEND=true ruby -v -Ilib -rprism -rbenchmark -e '300.times { p Benchmark.realtime { Dir.glob("lib/**/*.rb") { |f| Prism.parse_file(f) } } }'
ruby 3.3.0: 0.215 => 0.251 (cext: 0.062)
ruby 3.3.0 YJIT: 0.118 => 0.113 (cext: 0.053)
truffleruby JVM: 0.101 => 0.054
jruby 9.4.6.0: 0.162 => 0.219
jruby 9.4.6.0 indy: 0.078 => 0.086
* For the record here are the numbers for using the String directly, without a StringIO-like object:
ruby 3.3.0: 0.215 => 0.234 (cext: 0.062)
ruby 3.3.0 YJIT: 0.118 => 0.111 (cext: 0.053)
truffleruby native: 0.101 => 0.053
jruby 9.4.6.0: 0.162 => 0.195
jruby 9.4.6.0 indy: 0.078 => 0.082
As we can see, that extra object adds a non-trivial overhead on CRuby interpreter and JRuby.
But we need to make it possible to use StringIO and SimpleStringIO interchangeably.
938677cbd2
- Add `x` prefix to malloc, calloc, realloc, and free
(eg: malloc -> xmalloc)
- By default, they are replaced with stdlib's functions at build
- You can use custom functions by defining `PRISM_CUSTOM_ALLOCATOR` macro
7a878af619
This PR fixes the following incompatibility AST for regexp match between Parser gem and Prism:
## Parser gem
Returns an `match_with_lvasgn` node:
```console
$ bundle exec ruby -rparser/ruby33 -ve 'p Parser::Ruby33.parse("/foo/ =~ bar")'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
s(:match_with_lvasgn,
s(:regexp,
s(:str, "foo"),
s(:regopt)),
s(:send, nil, :bar))
```
## Prism (`Prism::Translation::Parser`)
### Before
Returns an `send` node:
```console
$ bundle exec ruby -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("/foo/ =~ bar")'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
s(:send,
s(:regexp,
s(:str, "foo"),
s(:regopt)), :=~,
s(:send, nil, :bar))
```
### After
Returns an `match_with_lvasgn` node:
```console
$ bundle exec ruby -rprism -rprism/translation/parser33 -ve 'p Prism::Translation::Parser33.parse("/foo/ =~ bar")'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
s(:match_with_lvasgn,
s(:regexp,
s(:str, "foo"),
s(:regopt)),
s(:send, nil, :bar))
```
## Background
Found due to incompatibility with RuboCop's `Performance/EndWith`, `Performance/StringInclude,
and `Performance/StartWith` cops.
## Note
This is the incompatibility when the receiver is a regular expression literal and `=~` is used.
Based on the node name `:match_with_lvasgn`, it appears that Prism's AST becomes more accurate
in cases like `visit_match_write_node` only.
However, as shown in the background, the current behavior of Parser gem is not like this.
Considering compatibility with the published AST of Parser gem, the AST incompatibility will be addressed.
This lvar-injecting feature appears to have not been supported by Parser gem for a long time:
https://github.com/whitequark/parser/issues/69#issuecomment-19506391
There seems to be no indication that it will be supported.
This PR prioritizes AST compatibility between the Parser gem and Prism.
However, it is unclear whether this is the best approach.
dff4abb170
The `RUBY_CODESIGN` environment variable is used by mkmf-generated
Makefile to sign extension bundles on macOS. The variable specifies a
key identifier to use for signing given by the user. However, the key
is usually stored in `$HOME/Library/Keychains` directory, and the test
suite creates a fake `$HOME` directory. This causes the test suite to
try to find the specified key from the fake home directory, which
results in a failure.
ddcfc65bf7
callcc's implementation is fundamentally incompatible with ASAN. Since
callcc is deprecated and almost never used, it's probably OK to disable
callcc when ruby is compiled with ASAN.
[Bug #20273]
This change makes `make_encmake.rb` expand all substitution variables
when replacing them in `enc/Makefile.in` to avoid propagating all
possibly referenced variables to the generated Makefile. The old
behavior, which don't expand make variables when generating Makefile,
was useful to temporarily override inherited variables like `cflags` in
`CFLAGS` at make-time. However, it's not a common use case and it
requires to propagate all possibly referenced variables properly
considering key name duplication between `enc/Makefile.in` and
`RbConfig::CONFIG`.
The documentation for `rb_enc_interned_str_cstr` notes that `enc` can be
a null pointer, but this currently causes a segmentation fault when
trying to autoload the encoding. This commit fixes the issue by checking
for NULL before calling `rb_enc_autoload`.
The `POSTLINK` variable had been used in the `LINK_SO` variable, which
is used to link shared extension libraries. However, the `POSTLINK`
variable had not been defined in the generated Makefile, so extension
libraries were not properly post-processed. It was not a critical issue
for the existing `POSTLINK` usage for darwin platforms, but it would be
a problem for Wasm/WASI platform, which requires *mandatory*
post-processing for shared extension libraries.
The `POSTLINK` variable had been used only for darwin platforms, but
it's now used for WebAssembly/WASI as well. To make shared extension
libraries properly post-processed, we need to append `POSTLINK` to
`LINK_SO` but it was done only for darwin platforms. This commit
generalizes the appending to all platforms.
In cases where a method accepts both keywords and an anonymous
keyword splat, the method was not marked as taking an anonymous
keyword splat. Fix that in the compiler.
Doing that broke handling of nil keyword splats in yjit, so
update yjit to handle that.
Add a test to check that calling a method that accepts both
a keyword argument and an anonymous keyword splat does not
modify a passed keyword splat hash.
Move the anon_kwrest check from setup_parameters_complex to
ignore_keyword_hash_p, and only use it if the keyword hash
is already a hash. This should speed things up slightly as
it avoids a check previously used for all callers of
setup_parameters_complex.
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
is_markable_object is called by rb_objspace_markable_object_p, which
may pass a T_NONE object. check_rvalue_consistency will fail if a T_NONE
object is passed in.
(https://github.com/ruby/irb/pull/888)
* Remove dead irb_level method
* Restructure workspace management
Currently, workspace is an attribute of IRB::Context in most use cases.
But when some workspace commands are used, like `pushws` or `popws`, a
workspace will be created and used along side with the original workspace
attribute.
This complexity is not necessary and will prevent us from expanding
multi-workspace support in the future.
So this commit introduces a @workspace_stack ivar to IRB::Context so IRB
can have a more natural way to manage workspaces.
* Fix pushws without args
* Always display workspace stack after related commands are used
61560b99b3
We don't need to check that the object is pointer to the GC heap in
vm_ccs_free because it is called during sweeping, which does not free
pages so it can never point to an object that is not on the GC heap.
These show gains from the recent optimization commits:
```
arg_splat
miniruby: 7346039.9 i/s
miniruby-before: 4692240.8 i/s - 1.57x slower
arg_splat_block
miniruby: 6539749.6 i/s
miniruby-before: 4358063.6 i/s - 1.50x slower
splat_kw_splat
miniruby: 5433641.5 i/s
miniruby-before: 3851048.6 i/s - 1.41x slower
splat_kw_splat_block
miniruby: 4916137.1 i/s
miniruby-before: 3477090.1 i/s - 1.41x slower
splat_kw_block
miniruby: 2912829.5 i/s
miniruby-before: 2465611.7 i/s - 1.18x slower
arg_splat_post
miniruby: 2195208.2 i/s
miniruby-before: 1860204.3 i/s - 1.18x slower
```
zsuper only speeds up in the post argument case, because
it was already set to use splatarray false in cases where
there were no post arguments.
These previously resulted in 2 array allocations, one for newarray
and one for concatarray. This replaces newarray and concatarray
with pushtoarray, and changes splatarray false to splatarray true,
which reduces it to 1 array allocation, in splatarray true.
This also sets VM_CALL_ARGS_SPLAT_MUT, so if the super method
accepts a positional splat, this will avoid an additional array
allocation on the callee side.
This optimization stopped being using when the splatkw VM instruction
was added. This change allows the optimization to apply again. This
also optimizes the following cases:
super(*ary, **kw, &block)
f(...)
super(...)
This optimizes cases such as:
super(arg, *ary)
super(arg, *ary, &block)
super(*ary, **kw)
super(*ary, kw: 1)
super(*ary, kw: 1, &block)
The super(*ary, **kw, &block) case does not use the splatarray false
optimization. This is also true of the send case, since the
introduction of the splatkw VM instruction. That will be fixed in
a later commit.
[Bug #20311]
`rb_define_class_under` assumes it's called from C and that the
reference might be held in a C global variable, so it adds the
class to the VM root.
In the case of `Struct.new('Name')` it's wasteful and make
the struct immortal.