[#114703] [Ruby master Bug#19875] Ruby 2.7 -> 3.1 Performance regression in String#count — "iz (Illia Zub) via ruby-core" <ruby-core@...>

Issue #19875 has been reported by iz (Illia Zub).

18 messages 2023/09/12

[#114774] [Ruby master Feature#19884] Make Safe Navigation Operator work on classes — "p8 (Petrik de Heus) via ruby-core" <ruby-core@...>

Issue #19884 has been reported by p8 (Petrik de Heus).

13 messages 2023/09/15

[#114796] [Ruby master Feature#19889] Let `Kernel.#require` search for files relative to the current working directory for non ./, ../ relative paths — "sawa (Tsuyoshi Sawada) via ruby-core" <ruby-core@...>

Issue #19889 has been reported by sawa (Tsuyoshi Sawada).

6 messages 2023/09/18

[#114803] [Ruby master Bug#19890] File#realine(chomp: true) slower/more allocations than readline.chomp! — "segiddins (Samuel Giddins) via ruby-core" <ruby-core@...>

Issue #19890 has been reported by segiddins (Samuel Giddins).

12 messages 2023/09/18

[#114817] [Ruby master Bug#19892] Build failure with 8f1b688177 — "vo.x (Vit Ondruch) via ruby-core" <ruby-core@...>

Issue #19892 has been reported by vo.x (Vit Ondruch).

8 messages 2023/09/19

[#114915] [Ruby master Feature#19905] Introduce `Queue#peek` — "hi@... (Joao Fernandes) via ruby-core" <ruby-core@...>

Issue #19905 has been reported by hi@joaofernandes.me (Joao Fernandes).

8 messages 2023/09/28

[ruby-core:114843] [Ruby master Bug#19890] File#realine(chomp: true) slower/more allocations than readline.chomp!

From: "Dan0042 (Daniel DeLorme) via ruby-core" <ruby-core@...>
Date: 2023-09-20 15:27:05 UTC
List: ruby-core #114843
Issue #19890 has been updated by Dan0042 (Daniel DeLorme).





Eregon (Benoit Daloze) wrote in #note-5:

> There such a functionality would cost an extra allocation per call (the s=
pecial variables objects is passed to the callee and that forces the alloca=
tion), which is a significant performance cost.



I have to say there's too many things I don't understand at all in this. Th=
e special variables object is passed from the caller to the callee, not the=
 other way? Does that mean a special variables object is allocated for any =
method call that *might* result in special variables, such as `#send` ? I'm=
 quite confused.



Well, regardless of how it is implemented internally, I think that prependi=
ng a module (as in my LogRegexpPerformance example) should be transparent t=
o pseudo-globals. I'm sure there's a way to handle that efficiently even in=
 TruffleRuby.=20







----------------------------------------

Bug #19890: File#realine(chomp: true) slower/more allocations than readline=
.chomp!

https://bugs.ruby-lang.org/issues/19890#change-104690



* Author: segiddins (Samuel Giddins)

* Status: Open

* Priority: Normal

* ruby -v: 3.2.2

* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN

----------------------------------------

On ruby 3.2.2 running the following script:



``` ruby

#!/usr/bin/env ruby



require 'rubygems'

require 'bundler/inline'



puts RUBY_VERSION



gemfile do

  source "https://rubygems.org"

  gem "benchmark-ipsa"

end



Benchmark.ipsa do |x|

  x.report("f.readline(chomp: true)") do

    File.open("/usr/share/dict/words") do |f|

      f.readline(chomp: true) until f.eof?

    end

  end

 =20

  x.report("f.readline.chomp!") do

    File.open("/usr/share/dict/words") do |f|

      until f.eof?

        s =3D f.readline

        s.chomp!

        s

      end

    end

  end

 =20

  x.report("f.readline.chomp") do

    File.open("/usr/share/dict/words") do |f|

      until f.eof?

        f.readline.chomp

      end

    end

  end

 =20

  x.compare!

end

```



I get the following (surprising) result:



```

3.2.2

Allocations -------------------------------------

	f.readline(chomp: true)

                      707931/1  alloc/ret       50/1  strings/ret

   f.readline.chomp!  235979/1  alloc/ret       50/1  strings/ret

    f.readline.chomp  471955/1  alloc/ret       50/1  strings/ret

Warming up --------------------------------------

f.readline(chomp: true)

                         1.000  i/100ms

   f.readline.chomp!     2.000  i/100ms

    f.readline.chomp     2.000  i/100ms

Calculating -------------------------------------

f.readline(chomp: true)

                         16.165  (=B1 6.2%) i/s -     81.000=20

   f.readline.chomp!     25.246  (=B1 7.9%) i/s -    126.000=20

    f.readline.chomp     20.997  (=B1 9.5%) i/s -    106.000=20



Comparison:

   f.readline.chomp!:       25.2 i/s

    f.readline.chomp:       21.0 i/s - 1.20x slower

f.readline(chomp: true):       16.2 i/s - 1.56x slower

```



I would expect `File#readline(chomp: true)` to be comparable to `s =3D f.re=
adline; s.chomp!; s` at a bare minimum, but it is slower and has more alloc=
ations even than `readline.chomp`









--=20

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

 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-c=
ore.ml.ruby-lang.org/

In This Thread