[1.8] speed

Do it exist some problems with 1.8.0 ?

I’ve just switched to rb_define_alloc_func() and with testunit-0.1.5 the
results are

pigeon% ruby -v
ruby 1.6.8 (2002-12-24) [i686-linux]
pigeon%

pigeon% make test
ruby tests/writer.rb
Loaded suite tests/writer
Started

Finished in 0.531359 seconds.
9 tests, 292 assertions, 0 failures, 0 errors
ruby tests/reader.rb
Loaded suite tests/reader
Started

Finished in 0.380022 seconds.
17 tests, 792 assertions, 0 failures, 0 errors
pigeon%

pigeon% ruby -v
ruby 1.8.0 (2002-12-24) [i686-linux]
pigeon%

pigeon% make test
ruby tests/writer.rb
Loaded suite tests/writer
Started

Finished in 0.943341 seconds.
9 tests, 292 assertions, 0 failures, 0 errors
ruby tests/reader.rb
Loaded suite tests/reader
Started

Finished in 0.728915 seconds.
17 tests, 792 assertions, 0 failures, 0 errors
pigeon%

Guy Decoux

Hi,

Do it exist some problems with 1.8.0 ?

I thought I fixed the performance, but there must be something left.

I’ve just switched to rb_define_alloc_func() and with testunit-0.1.5 the
results are

I want to profile the code. Is your test suite the one bundled with testunit?

						matz.
···

In message “[1.8] speed” on 02/12/27, ts decoux@moulon.inra.fr writes:

I want to profile the code. Is your test suite the one bundled with
testunit?

yes. I've seen this big slowdown only with bz2 : libbzip2 internally use
big buffers to decompress the data, with bz2 these buffers are managed by
ruby (ruby_xmalloc). This means that each time I call ::new, the GC is
called.

This is only how I can explain this slowdown with bz2

Guy Decoux

Hi,

···

At Sun, 29 Dec 2002 17:59:43 +0900, ts wrote:

yes. I’ve seen this big slowdown only with bz2 : libbzip2 internally use
big buffers to decompress the data, with bz2 these buffers are managed by
ruby (ruby_xmalloc). This means that each time I call ::new, the GC is
called.

I guess this issue and [ruby-talk:59662] concern with following
change. GC only knows “big buffers” were allocated, but
doesn’t know whether they’re refered by live objects, so the
live memories amount would be estimated too small than the
allocated.

Fri Oct 11 00:24:57 2002 Nobuyoshi Nakada nobu.nokada@softhome.net

* gc.c (ruby_xmalloc, ruby_xrealloc): restrict total allocation
  size according to memories consumed by live objects.
  [ruby-dev:18482]

* gc.c (gc_sweep): estimate how live objects consume memories.


Nobu Nakada

yes.

I wanted to say no :slight_smile:

This is only how I can explain this slowdown with bz2

There is something else

1.6.8 / ruby_xmalloc

pigeon% make test
[...]
Finished in 0.549302 seconds.
[...]
Finished in 0.378875 seconds.
pigeon%

1.6.8 / malloc

pigeon% make test
[...]
Finished in 0.413842 seconds.
[...]
Finished in 0.291134 seconds.
pigeon%

1.8.0 / ruby_xmalloc

pigeon% make test
[...]
Finished in 0.946439 seconds.
[...]
Finished in 0.729225 seconds.
pigeon%

1.8.0 / malloc

pigeon% make test
[...]
Finished in 0.527818 seconds.
[...]
Finished in 0.50959 seconds.
[...]
pigeon%

Guy Decoux

I want to profile the code. Is your test suite the one bundled with
testunit?

yes. I’ve seen this big slowdown only with bz2 : libbzip2 internally use
big buffers to decompress the data, with bz2 these buffers are managed by
ruby (ruby_xmalloc). This means that each time I call ::new, the GC is
called.

This is only how I can explain this slowdown with bz2

Remember the “speed differences” I posted a while ago?
Same issue.

gc_sweep() got called for each allocation of 100kB, meaning it was ran
about 100 times more often for 1.7.3 than for 1.6.8. If I change the
allocation size to 100 bytes (instead of 100 kB) 1.7.3 speeds up to match
1.6.8

Suggestion to fix: the GC should not run, unless a threshold on the amount
of allocations is crossed. (But my theory on gc is weak, so I am probably
missing some things here.)

Bye,
Kero.

±-- Kero ------------------------------ kero@chello.nl —+

Don’t split your mentality without thinking twice |
Proud like a God – Guano Apes |
±-- M38c ---------- http://httpd.chello.nl/k.vangelder —+

I guess this issue and [ruby-talk:59662] concern with following
change. GC only knows "big buffers" were allocated, but
doesn't know whether they're refered by live objects, so the
live memories amount would be estimated too small than the
allocated.

Well, I have also changed Data_Make_Struct to be sure that it call also
malloc() rather than ruby_xmalloc() and it seems to have a problem with
the GC. It is called more often

   1.8.0

11.32 0.13 0.06 379092 0.00 0.00 rb_gc_mark
  7.55 0.23 0.04 22 1.82 4.26 gc_sweep
  3.77 0.31 0.02 204403 0.00 0.00 rb_gc_mark_children
  1.89 0.40 0.01 177487 0.00 0.00 mark_source_filename

  1.6.8

  2.86 0.22 0.01 8681 0.00 0.00 rb_gc_mark
  2.86 0.34 0.01 2 5.00 5.00 gc_sweep
  0.00 0.35 0.00 15069 0.00 0.00 mark_source_filename

Guy Decoux

  * gc.c (ruby_xmalloc, ruby_xrealloc): restrict total allocation
    size according to memories consumed by live objects.
    [ruby-dev:18482]

  * gc.c (gc_sweep): estimate how live objects consume memories.

Yes, this is this that it don't like.

With one my test (reader.rb) it never call the GC with 1.6.8, but call it
many times with 1.8 (this is a version of bz2 with malloc() for
Data_Make_Struct() and the libbzip2 buffers).

Guy Decoux

gc_sweep() got called for each allocation of 100kB, meaning it was ran
about 100 times more often for 1.7.3 than for 1.6.8. If I change the
allocation size to 100 bytes (instead of 100 kB) 1.7.3 speeds up to match
1.6.8

Well, the problem is easy to understand if you look the source.

The patch is described

  * gc.c (ruby_xmalloc, ruby_xrealloc): restrict total allocation
    size according to memories consumed by live objects.
    [ruby-dev:18482]

  * gc.c (gc_sweep): estimate how live objects consume memories.

Unfortunately this is wrong : ruby don't estimate the size of *all*
objects but only the size of *some* objects (like T_OBJECT, T_ARRAY, ...)
it don't even try to correct this value to have a real estimation of the
memory, and even if it will try do it it will have a problem.

The problem is that ruby has selected a subpopulation and this
subpopulation is not representative of all objects.

Guy Decoux