Граф коммитов

295 Коммитов

Автор SHA1 Сообщение Дата
Nobuyoshi Nakada 05229cef45
Improve `String#slice!` performance
Instead of searching twice to extract and to delete, extract and
delete the found position at the first search.

This makes faster nearly twice, for regexps and strings.

|              |compare-ruby|built-ruby|
|:-------------|-----------:|---------:|
|regexp-short  |      2.143M|    3.918M|
|regexp-long   |    105.162k|  205.410k|
|string-short  |      3.789M|    7.964M|
|string-long   |      1.301M|    2.457M|
2020-01-31 17:12:05 +09:00
Kazuhiro NISHIYAMA c90fc55a1f Drop executable bit of *.{yml,h,mk.tmpl} 2020-01-22 16:04:38 +09:00
Lourens Naudé 40c57ad4a1 Let execution context local storage be an ID table 2020-01-11 14:40:36 +13:00
Lourens Naudé 592d7ceeeb Speeds up fallback to Hash#default_proc in rb_hash_aref by removing a method call 2020-01-08 18:09:52 +09:00
David Rodríguez f48655d04d Remove unneeded exec bits from some files
I noticed that some files in rubygems were executable, and I could think
of no reason why they should be.

In general, I think ruby files should never have the executable bit set
unless they include a shebang, so I run the following command over the
whole repo:

```bash
find . -name '*.rb' -type f -executable -exec bash -c 'grep -L "^#!" $1 || chmod -x $1' _ {} \;
```
2019-11-09 21:36:30 +09:00
Nobuyoshi Nakada 8390057d1e
Benchmark for [Feature #16155] 2019-10-22 22:49:48 +09:00
Dylan Thacker-Smith b970259044 Stop making a redundant hash copy in Hash#dup (#2489)
* Stop making a redundant hash copy in Hash#dup

It was making a copy of the hash without rehashing, then created an
extra copy of the hash to do the rehashing.  Since rehashing creates
a new copy already, this change just uses that rehashing to make
the copy.

[Bug #16121]

* Remove redundant Check_Type after to_hash

* Fix freeing and clearing destination hash in Hash#initialize_copy

The code was assuming the state of the destination hash based on the
source hash for clearing any existing table on it. If these don't match,
then that can cause the old table to be leaked. This can be seen by
compiling hash.c with `#define HASH_DEBUG 1` and running the following
script, which will crash from a debug assertion.

```ruby
h = 9.times.map { |i| [i, i] }.to_h
h.send(:initialize_copy, {})
```

* Remove dead code paths in rb_hash_initialize_copy

Given that `RHASH_ST_TABLE_P(h)` is defined as `(!RHASH_AR_TABLE_P(h))`
it shouldn't be possible for a hash to be neither of these, so there
is no need for the removed `else if` blocks.

* Share implementation between Hash#replace and Hash#initialize_copy

This also fixes key rehashing for small hashes backed by an array
table for Hash#replace.  This used to be done consistently in ruby
2.5.x, but stopped being done for small arrays in ruby 2.6.x.

This also bring optimization improvements that were done for
Hash#initialize_copy to Hash#replace.

* Add the Hash#dup benchmark
2019-10-21 17:29:21 +09:00
Dylan Thacker-Smith a1fda16b23 Optimize Array#flatten and flatten! for already flattened arrays (#2495)
* Optimize Array#flatten and flatten! for already flattened arrays
* Add benchmark for Array#flatten and Array#flatten!

[Bug #16119]
2019-09-28 01:24:24 +09:00
Takashi Kokubun 41e3c204fd
Reduce ISeq size of mjit_exec benchmark
to avoid unwanted memory pressure
2019-09-26 22:13:31 +09:00
Takashi Kokubun 4a4c502825
Add special runner to benchmark mjit_exec
I wanted to dynamically generate benchmark cases to test various number
of methods. Thus I added a dedicated runner of benchmark-driver.
2019-09-26 16:34:40 +09:00
Takashi Kokubun b414999370
Add a benchmark for JIT-ed code dispatch 2019-09-21 16:09:52 +09:00
卜部昌平 d74fa8e55c reuse cc->call
I noticed that in case of cache misshit, re-calculated cc->me can
be the same method entry than the pevious one.  That is an okay
situation but can't we partially reuse the cache, because cc->call
should still be valid then?

One thing that has to be special-cased is when the method entry
gets amended by some refinements.  That happens behind-the-scene
of call cache mechanism.  We have to check if cc->me->def points to
the previously saved one.

Calculating -------------------------------------
                          trunk        ours
vm2_poly_same_method     1.534M      2.025M i/s -      6.000M times in 3.910203s 2.962752s

Comparison:
             vm2_poly_same_method
                ours:   2025143.9 i/s
               trunk:   1534447.2 i/s - 1.32x  slower
2019-09-19 15:18:10 +09:00
Takashi Kokubun ff462bc6c3
Add a benchmark for opt_regexpmatch2
vm2_regexp was for opt_regexpmatch1.
2019-09-02 13:46:33 +09:00
Nobuyoshi Nakada 07e42e88d9
Close created files [ci skip] 2019-08-10 11:26:23 +09:00
Masato Ohba 6902824729
Fix typo in comment [ci skip]
s/Thtread/Thread
2019-08-10 09:35:28 +09:00
Yaw Boakye 6bb3618f28
n+1 to include n in range
Python's range stop right before n, which means factL never returns the correct result.

Closes: https://github.com/ruby/ruby/pull/1982
2019-08-05 09:04:32 +09:00
Yusuke Endoh 086ffe72c7 Revert "Revert "Add a specialized instruction for `.nil?` calls""
This reverts commit a0980f2446.

Retry for macOS Mojave.
2019-08-02 23:25:38 +09:00
Yusuke Endoh a0980f2446 Revert "Add a specialized instruction for `.nil?` calls"
This reverts commit 9faef3113f.

It seemed to cause a failure on macOS Mojave, though I'm unsure how.
https://rubyci.org/logs/rubyci.s3.amazonaws.com/osx1014/ruby-master/log/20190802T034503Z.fail.html.gz

This tentative revert is to check if the issue is actually caused by the
change or not.
2019-08-02 15:03:34 +09:00
Aaron Patterson 9faef3113f
Add a specialized instruction for `.nil?` calls
This commit adds a specialized instruction for called to `.nil?`.  It is
about 27% faster than master in the case where the object is nil or not
nil.  In the case where an object implements `nil?`, I think it may be
slightly slower.  Here is a benchmark:

```ruby
require "benchmark/ips"

class Niller
  def nil?; true; end
end

not_nil = Object.new
xnil = nil
niller = Niller.new

Benchmark.ips do |x|
  x.report("nil?")    { xnil.nil? }
  x.report("not nil") { not_nil.nil? }
  x.report("niller")   { niller.nil? }
end
```

On Ruby master:

```
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   429.195k i/100ms
             not nil   437.889k i/100ms
              niller   437.935k i/100ms
Calculating -------------------------------------
                nil?     20.166M (± 8.1%) i/s -    100.002M in   5.002794s
             not nil     20.046M (± 7.6%) i/s -     99.839M in   5.020086s
              niller     22.467M (± 6.1%) i/s -    112.111M in   5.013817s
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   449.660k i/100ms
             not nil   433.836k i/100ms
              niller   443.073k i/100ms
Calculating -------------------------------------
                nil?     19.997M (± 8.8%) i/s -     99.375M in   5.020458s
             not nil     20.529M (± 7.0%) i/s -    102.385M in   5.020689s
              niller     21.796M (± 8.0%) i/s -    108.110M in   5.002300s
[aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   402.119k i/100ms
             not nil   438.968k i/100ms
              niller   398.226k i/100ms
Calculating -------------------------------------
                nil?     20.050M (±12.2%) i/s -     98.519M in   5.008817s
             not nil     20.614M (± 8.0%) i/s -    102.280M in   5.004531s
              niller     22.223M (± 8.8%) i/s -    110.309M in   5.013106s

```

On this branch:

```
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   468.371k i/100ms
             not nil   456.517k i/100ms
              niller   454.981k i/100ms
Calculating -------------------------------------
                nil?     27.849M (± 7.8%) i/s -    138.169M in   5.001730s
             not nil     26.417M (± 8.7%) i/s -    131.020M in   5.011674s
              niller     21.561M (± 7.5%) i/s -    107.376M in   5.018113s
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   477.259k i/100ms
             not nil   428.712k i/100ms
              niller   446.109k i/100ms
Calculating -------------------------------------
                nil?     28.071M (± 7.3%) i/s -    139.837M in   5.016590s
             not nil     25.789M (±12.9%) i/s -    126.470M in   5.011144s
              niller     20.002M (±12.2%) i/s -     98.144M in   5.001737s
[aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb
Warming up --------------------------------------
                nil?   467.676k i/100ms
             not nil   445.791k i/100ms
              niller   415.024k i/100ms
Calculating -------------------------------------
                nil?     26.907M (± 8.0%) i/s -    133.755M in   5.013915s
             not nil     25.319M (± 7.9%) i/s -    125.713M in   5.007758s
              niller     19.569M (±11.8%) i/s -     96.286M in   5.008533s
```

Co-Authored-By: Ashe Connor <kivikakk@github.com>
2019-07-31 16:21:25 -07:00
Takashi Kokubun 1392b821b9
Explain what's benchmark/lib/load.rb [ci skip]
I'm actually not using this, but ko1 is.
2019-07-20 15:33:55 +09:00
Samuel Williams 56fcf98849
Add note about setting `vm.max_map_count` for Linux. 2019-07-18 20:54:55 +12:00
Samuel Williams 9b28eefeb2
Add benchmark to help diagnose performance regression.
See https://bugs.ruby-lang.org/issues/16009 for more details.
2019-07-18 11:13:49 +12:00
Nobuyoshi Nakada ae599db22f
* remove trailing spaces. 2019-07-12 17:57:28 +09:00
Samuel Williams 012e954b47
Improved fiber benchmarks. Increase number of iterations. 2019-07-12 11:56:51 +12:00
Hiroshi SHIBATA e8a2521abe
Adjust memory_status.rb under the tool directory. 2019-07-02 21:39:22 +09:00
Jeremy Evans 11c311e36f Use realpath(3) instead of custom realpath implementation if available
This approach is simpler than the previous approach which tries to
emulate realpath(3).  It also performs much better on both Linux and
OpenBSD on the included benchmarks.

By using realpath(3), we can better integrate with system security
features such as OpenBSD's unveil(2) system call.

This does not use realpath(3) on Windows even if it exists, as the
approach for checking for absolute paths does not work for drive
letters.  This can be fixed without too much difficultly, though until
Windows defines realpath(3), there is no need to do so.

For File.realdirpath, where the last element of the path is not
required to exist, fallback to the previous approach, as realpath(3)
on most operating systems requires the whole path be valid (per POSIX),
and the operating systems where this isn't true either plan to conform
to POSIX or may change to conform to POSIX in the future.

glibc realpath(3) does not handle /path/to/file.rb/../other_file.rb
paths, returning ENOTDIR in that case.  Fallback to the previous code
if realpath(3) returns ENOTDIR.

glibc doesn't like realpath(3) usage for paths like /dev/fd/5,
returning ENOENT even though the path may appear to exist in the
filesystem.  If ENOENT is returned and the path exists, then fall
back to the default approach.
2019-07-01 11:46:30 -07:00
Samuel Williams 3fd83cb6fc Improve benchmarks and tests for threads. 2019-06-19 20:39:10 +12:00
Takashi Kokubun caa90202c9
Make sure to suppress .irbrc on benchmark
By the way, this is already improved by nobu:

```
$ benchmark-driver benchmark/irb_exec.yml --rbenv '2.6.3;2.7.0-preview1;before;after' -v
2.6.3: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
2.7.0-preview1: ruby 2.7.0preview1 (2019-05-31 trunk c55db6aa27) [x86_64-linux]
before: ruby 2.7.0dev (2019-06-10T21:13:14+09:00 master 973fd18f11) [x86_64-linux]
after: ruby 2.7.0dev (2019-06-10T21:18:56+09:00 master 976c689ad4) [x86_64-linux]
Calculating -------------------------------------
                          2.6.3  2.7.0-preview1      before       after
            irb_exec     11.868           5.872       6.297      10.278 i/s -      30.000 times in 2.527776s 5.108997s 4.764167s 2.918821s

Comparison:
                         irb_exec
               2.6.3:        11.9 i/s
               after:        10.3 i/s - 1.15x  slower
              before:         6.3 i/s - 1.88x  slower
      2.7.0-preview1:         5.9 i/s - 2.02x  slower

```
2019-06-10 22:04:52 +09:00
Takashi Kokubun 973fd18f11
Add a benchmark of irb boot time
```
$ benchmark-driver benchmark/irb_exec.yml --rbenv '2.6.3;2.7.0-preview1'
Calculating -------------------------------------
                          2.6.3  2.7.0-preview1
            irb_exec     11.844           5.171 i/s -      30.000 times in 2.532887s 5.801960s

Comparison:
                         irb_exec
               2.6.3:        11.8 i/s
      2.7.0-preview1:         5.2 i/s - 2.29x  slower
```
2019-06-10 21:13:14 +09:00
Takashi Kokubun 0a29dc87e6
Optimize CGI.escapeHTML by reducing buffer extension
and switch-case branches.

Buffer allocation optimization using `ALLOCA_N` would be the main
benefit of patch. It eliminates the O(N) buffer extensions.

It also reduces the number of branches using escape table like
https://mattn.kaoriya.net/software/lang/c/20160817011915.htm.

Closes: https://github.com/ruby/ruby/pull/2226

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
2019-06-05 21:07:04 +09:00
Takashi Kokubun 71b14affc6
Revert "Optimize CGI.escapeHTML by reducing buffer extension"
This reverts commit 8d81e59aa7.

`ALLOCA_N` does not check stack overflow unlike ALLOCV. I'll fix it and
re-commit it again.
2019-06-05 11:00:54 +09:00
Takashi Kokubun 8d81e59aa7
Optimize CGI.escapeHTML by reducing buffer extension
and switch-case branches.

Buffer allocation optimization using `ALLOCA_N` would be the main
benefit of patch. It eliminates the O(N) buffer extensions.

It also reduces the number of branches using escape table like
https://mattn.kaoriya.net/software/lang/c/20160817011915.htm.

Closes: https://github.com/ruby/ruby/pull/2226

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
Co-authored-by: Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
2019-06-05 10:08:55 +09:00
Takashi Kokubun f630359d9b
Add a benchmark using IRB::Color
I heard actually this part would not be a bottleneck for rendering
because writing anything to terminal takes way longer time anyway, but I
thought this benchmark script might be useful for benchmarking Ruby
itself.
2019-06-01 20:07:50 +09:00
Lourens Naudé a47f598d77
Reduce ONIG_NREGION from 10 to 4: power of 2 and testing revealed most pattern matches are less than or equal to 4 results
Closes: https://github.com/ruby/ruby/pull/2135
2019-05-07 21:58:55 +09:00
Nobuyoshi Nakada 77440e949b
Improve performance of case-conversion methods 2019-05-03 23:59:18 +09:00
nobu e1eb54b99d string.c: improve splitting into chars
* string.c (rb_str_split_m): improve splitting into chars by an
  empty string, without a regexp.

    Comparison:
                           to_chars-1
              built-ruby:   1273527.6 i/s
            compare-ruby:    189423.3 i/s - 6.72x  slower

                          to_chars-10
              built-ruby:    120993.5 i/s
            compare-ruby:     37075.8 i/s - 3.26x  slower

                         to_chars-100
              built-ruby:     15646.4 i/s
            compare-ruby:      4012.1 i/s - 3.90x  slower

                        to_chars-1000
              built-ruby:      1295.1 i/s
            compare-ruby:       408.5 i/s - 3.17x  slower

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 05:34:46 +00:00
eregon f2d6338574 benchmark/app_aobench.rb: complete commented code to write the image to a file
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-21 12:31:29 +00:00
eregon 32e259f097 benchmark/app_aobench.rb: remove extra printf arguments
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-21 12:31:20 +00:00
eregon dfe6918604 benchmark/app_aobench.rb: move `srand(0)` at the top
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-21 12:31:10 +00:00
mame 8a294e0f20 benchmark/app_aobench.rb: add `srand(0)`
To prevent noise for benchmark result.  Just for the case.
[Bug #15552]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-21 07:29:00 +00:00
mame be3a0c7042 benchmark/app_aobench.rb: add a magic comment
To support the change of default encoding.
It had not worked correctly since 2.0 :-)
[Bug #15552]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-21 07:13:32 +00:00
nobu 72ad092960 Time.strptime benchmarks
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-07 02:05:21 +00:00
mrkn d41fb6ce0b benchmark/range_last.yml: remove needless prelude
[ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-06 15:46:21 +00:00
mrkn bf6584b5d0 benchmark/range_last.yml: add benchmark cases
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-06 00:46:35 +00:00
mrkn 56a6dd66d4 benchmark/range_last.yml: add a benchmark of Range#last
[ci skip]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-05 10:07:40 +00:00
mrkn 8d473272db benchmark/complex_float_*.yml: New benchmarks
Add new benchmark scripts for binary operations of Complex with float
components.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-01 12:20:04 +00:00
shyouhei bc64df876e delete emacs mode lines [ci skip]
These settings are now covered by .dir-locals.el.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66584 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-27 06:12:09 +00:00
k0kubun 17ca870a4d benchmark/app_erb.yml: remove unused variable
3efcb74036 (r31762996)

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-22 01:43:45 +00:00
tenderlove bf41340ebb Add benchmark for hash small literals
Co-Authored-By: Krzysztof Rybka <krzysztof.rybka@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66256 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 18:20:11 +00:00
samuel 5547c65bdf Rename fiber chain benchmark.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-20 10:17:08 +00:00