[#100309] How to use backport custom field — Jun Aruga <jaruga@...>
Please allow my ignorance.
9 messages
2020/10/06
[#100310] Re: How to use backport custom field
— "NARUSE, Yui" <naruse@...>
2020/10/06
IkJhY2twb3J0IGN1c3RvbSBmaWVsZCIgaXMgb25seSBhdmFpbGFibGUgZm9yIHRpY2tldHMgd2hv
[#100311] Re: How to use backport custom field
— Jun Aruga <jaruga@...>
2020/10/06
On Tue, Oct 6, 2020 at 4:44 PM NARUSE, Yui <[email protected]> wrote:
[#100314] Re: How to use backport custom field
— "NARUSE, Yui" <naruse@...>
2020/10/06
VGhhbmsgeW91IGZvciBjb25maXJtYXRpb24uCkkgY2hlY2tlZCBhZ2FpbiBhbmQgdG8gZWRpdCBi
[#100322] Re: How to use backport custom field
— Jun Aruga <jaruga@...>
2020/10/07
On Tue, Oct 6, 2020 at 7:25 PM NARUSE, Yui <[email protected]> wrote:
[#100326] Re: How to use backport custom field
— "NARUSE, Yui" <naruse@...>
2020/10/07
SSBhZGRlZCB5b3UgdG8gIlJlcG9ydGVyIiByb2xlIGluIHRoZSBwcm9qZWN0CgoyMDIw5bm0MTDm
[#100327] Re: How to use backport custom field
— Jun Aruga <jaruga@...>
2020/10/07
On Wed, Oct 7, 2020 at 1:42 PM NARUSE, Yui <[email protected]> wrote:
[ruby-core:100524] [Ruby master Feature#17206] Introduce new Regexp option to avoid global MatchData allocations
From:
eregontp@...
Date:
2020-10-24 14:51:50 UTC
List:
ruby-core #100524
Issue #17206 has been updated by Eregon (Benoit Daloze).
I took a quick look, the logic to set $~ is here:
https://github.com/ruby/ruby/blob/148961adcd0704d964fce920330a6301b9704c25/re.c#L1608-L1623
It does not seem so expensive, but the region is allocated which xmalloc() which is probably not so cheap (there is also a `rb_gc()` call in there, hopefully it's not hit in practice).
`rb_backref_set()` goes through a few indirections (it needs to reach the caller frame typically), but it does not seem too expensive either.
I think it would be valuable to investigate further what's actually expensive for setting `$~` and how can that be optimized.
A hacky Regexp flag to manually optimize `match/=~/===` calls doesn't seem a good way to me.
The caller code knows if it needs $~, etc, not the Regexp literal.
----------------------------------------
Feature #17206: Introduce new Regexp option to avoid global MatchData allocations
https://bugs.ruby-lang.org/issues/17206#change-88146
* Author: fatkodima (Dima Fatko)
* Status: Open
* Priority: Normal
----------------------------------------
Originates from https://bugs.ruby-lang.org/issues/17030
When this option is specified, ruby will not create global `MatchData` objects, when not explicitly needed by the method.
If the new option is named `f`, we can write as `/o/f`, and `grep(/o/f)` is faster than `grep(/o/)`.
This speeds up not only `grep`, but also `all?`, `any?`, `case` and so on.
Many people have written code like this:
```ruby
IO.foreach("foo.txt") do |line|
case line
when /^#/
# do nothing
when /^(\d+)/
# using $1
when /xxx/
# using $&
when /yyy/
# not using $&
else
# ...
end
end
```
This is slow, because of the above mentioned problem.
Replacing `/^#/` with `/^#/f`, and `/yyy/` with `/yyy/f` will make it faster.
Some benchmarks - https://bugs.ruby-lang.org/issues/17030#note-9 which show `2.5x` to `5x` speedup.
PR: https://github.com/ruby/ruby/pull/3455
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>