Aaron Patterson e4e054e3ce Speed up setting the backref match object
This patch speeds up setting the backref match object by avoiding some
memcopies.  Take the following code for example:

```ruby
"hello world" =~ /hello/
p $~
```

When the RE matches the string, we have to set the Match object in the
backref global.  So we would allocate a match object[^1] and use
`rb_reg_region_copy`[^2] to make a deep copy of the stack allocated
`re_registers` struct[^3] in to the newly created Ruby object.  This
could possibly trigger GC[^4], and would allocate new memory.

This patch makes a shallow copy of the `re_registers` struct on to the
Match object allowing the match object to manage the `re_registers`
pointer and also avoiding some calls to `xmalloc` and some manual
memcopy.

Benchmark looks like this:

```ruby

require "benchmark/ips"

def test_re thing
  thing =~ /hello/
end

Benchmark.ips do |x|
  x.report("re hit") do
    test_re "hello world"
  end

  x.report("re miss") do
    test_re "world"
  end
end
```

Before this patch:

```
$ ruby -v test.rb
ruby 3.2.0dev (2022-07-27T22:29:00Z master 4ad69899b7) [arm64-darwin21]
Ignoring bcrypt-3.1.16 because its extensions are not built. Try: gem pristine bcrypt --version 3.1.16
Warming up --------------------------------------
              re hit   345.401k i/100ms
             re miss   673.584k i/100ms
Calculating -------------------------------------
              re hit      3.452M (± 0.5%) i/s -     17.270M in   5.002535s
             re miss      6.736M (± 0.4%) i/s -     34.353M in   5.099593s
```

After this patch:

```
$ ./ruby -v test.rb
ruby 3.2.0dev (2022-08-01T21:24:12Z less-memcpy 0ff2a56606) [arm64-darwin21]
Warming up --------------------------------------
              re hit   419.578k i/100ms
             re miss   673.251k i/100ms
Calculating -------------------------------------
              re hit      4.201M (± 0.7%) i/s -     21.398M in   5.093593s
             re miss      6.716M (± 0.4%) i/s -     33.663M in   5.012756s
```

Matches get faster and misses maintain the same speed

[^1]: 24204d54ab/re.c (L1737)
[^2]: 24204d54ab/re.c (L1738)
[^3]: 24204d54ab/re.c (L1686)
[^4]: 24204d54ab/re.c (L981)
2022-08-02 09:04:04 -07:00
2022-03-30 20:36:31 +13:00
2022-07-27 18:42:27 +09:00
2022-07-27 18:42:27 +09:00
2022-05-20 14:45:46 -07:00
2022-08-02 11:04:28 +02:00
2022-07-21 09:42:04 -07:00
2022-08-02 11:04:28 +02:00
2022-07-21 09:42:04 -07:00
2022-03-31 08:35:39 +09:00
2022-08-02 11:04:28 +02:00
2022-05-09 07:29:37 +09:00
2022-07-22 21:59:58 +09:00
2022-06-23 22:52:45 +09:00
2022-03-24 10:03:51 -04:00
2022-07-21 09:42:04 -07:00
2022-06-02 16:05:35 +09:00
2022-08-02 11:04:28 +02:00
2022-07-21 09:42:04 -07:00
2022-07-27 18:42:27 +09:00
2022-07-21 09:42:04 -07:00
2022-05-03 09:07:39 -04:00
2022-07-21 09:42:04 -07:00
2022-07-27 18:42:27 +09:00
2022-07-21 09:42:04 -07:00
2022-06-10 22:22:16 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
GPL
2022-08-02 11:04:28 +02:00
2022-07-21 09:42:04 -07:00
2022-08-02 11:04:28 +02:00
2022-07-21 09:42:04 -07:00
2022-07-27 18:42:27 +09:00
2022-07-28 09:02:23 +09:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-15 09:21:07 -04:00
2022-07-27 18:42:27 +09:00
2022-06-15 09:40:54 -07:00
2022-06-15 10:52:37 -07:00
2022-08-01 12:34:03 +09:00
2022-08-01 10:36:36 +09:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-27 18:42:27 +09:00
2022-07-21 09:42:04 -07:00
2022-07-12 11:48:10 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-28 23:46:07 +09:00
2022-07-28 23:46:07 +09:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-08-02 09:04:04 -07:00
2022-03-11 15:08:23 +09:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-04-09 17:43:46 +09:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-26 18:33:21 +09:00
2022-06-09 13:40:21 -05:00
2022-07-21 09:42:04 -07:00
2022-07-27 18:42:27 +09:00
2022-07-21 09:42:04 -07:00
2022-08-02 11:04:28 +02:00
2022-07-21 09:42:04 -07:00
2022-03-29 18:14:33 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:02:45 -04:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-08-02 02:38:08 +09:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-03-24 10:03:51 -04:00
2022-07-27 18:42:27 +09:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00
2022-07-21 09:42:04 -07:00

Actions Status: MinGW Actions Status: MJIT Actions Status: Ubuntu Actions Status: Windows AppVeyor status Travis Status Cirrus Status

What is Ruby?

Ruby is an interpreted object-oriented programming language often used for web development. It also offers many scripting features to process plain text and serialized files, or manage system tasks. It is simple, straightforward, and extensible.

Features of Ruby

  • Simple Syntax
  • Normal Object-oriented Features (e.g. class, method calls)
  • Advanced Object-oriented Features (e.g. mix-in, singleton-method)
  • Operator Overloading
  • Exception Handling
  • Iterators and Closures
  • Garbage Collection
  • Dynamic Loading of Object Files (on some architectures)
  • Highly Portable (works on many Unix-like/POSIX compatible platforms as well as Windows, macOS, etc.) cf. https://github.com/ruby/ruby/blob/master/doc/maintainers.rdoc#label-Platform+Maintainers

How to get Ruby with Git

For a complete list of ways to install Ruby, including using third-party tools like rvm, see:

https://www.ruby-lang.org/en/downloads/

The mirror of the Ruby source tree can be checked out with the following command:

$ git clone https://github.com/ruby/ruby.git

There are some other branches under development. Try the following command to see the list of branches:

$ git ls-remote https://github.com/ruby/ruby.git

You may also want to use https://git.ruby-lang.org/ruby.git (actual master of Ruby source) if you are a committer.

Ruby home page

https://www.ruby-lang.org/

Documentation

Mailing list

There is a mailing list to discuss Ruby. To subscribe to this list, please send the following phrase:

subscribe

in the mail body (not subject) to the address ruby-talk-request@ruby-lang.org.

Copying

See the file COPYING.

Feedback

Questions about the Ruby language can be asked on the Ruby-Talk mailing list or on websites like https://stackoverflow.com.

Bugs should be reported at https://bugs.ruby-lang.org. Read "Reporting Issues" for more information.

Contributing

See "Contributing to Ruby", which includes setup and build instructions.

The Author

Ruby was originally designed and developed by Yukihiro Matsumoto (Matz) in 1995.

matz@ruby-lang.org

Description
Languages
Ruby 58.9%
C 29.5%
Rust 6.1%
C++ 2.9%
Yacc 0.9%
Other 1.6%