ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Hongli Lai <hongli@plan99.net>
To: ruby-core@ruby-lang.org
Subject: Re: Copy-on-write friendly garbage collector
Date: Sat, 8 Mar 2008 01:22:05 +0900	[thread overview]
Message-ID: <47D16BBE.9060005@plan99.net> (raw)
In-Reply-To: <20080307152052.GK25415@atdesk.com>

Paul Brannan wrote:
> If what Matz says is true, that it's 8-10% slower than the current
> implementation, isn't that enough of a yellow flag?
> 
> Is it possible to improve performance of the patch?  I looked over the
> implementation for a little while, but didn't see any obvious
> opportunities for improvement.  I'd be interested to see profiler output
> to see where time is being spent.

I've looked for ways to optimize it, but the bitfield implementation 
already seems to be near-optimal. All the old garbage collector had to 
do was setting a flag. But this one has to:
1. Call a mark function.
2. Find the heap that the object is on. This operation is O(n), with n = 
the number of heaps. Though it uses a cache to speed up the average case.
3. Calculate the location in the bitfield. This requires a division (/) 
and a remainder (%) operation.

(1), function call overhead, could be solved with aggressive inlining 
and aggressive use of macros. The downside is excessive use of macros 
would make the code very hard to read.

(2) could be solved as follows: put an index field in each VALUE object. 
Then the mark function can find the location of the heap (and thus the 
bitfield) in O(1) time. But this will make each VALUE object at least 4 
bytes bigger (on x86). Is this increase in memory usage acceptable for 
8-10% performance gain?
I've also thought about ways to make this operation O(1) without an 
index field. *Maybe* it is possible by ensuring that heap addresses are 
aligned on some multiple of an integer constant. Then finding the heap 
from an object would only involve the extraction of a few bits in the 
object address. But this is highly platform-dependent and I'm not sure 
whether it is viable to implement this without making the code 
unmaintainable and unportable.

(3): I don't think this can be solved.

In any case, all of these operations need at least several pointer 
dereferences. The old GC only needed 1.

And because Windows does not support fork(), the garbage collector 
doesn't have to use a bit field for marking when compiled on Windows. 
This could be configured with a macro.

  reply	other threads:[~2008-03-07 16:23 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-03  9:48 Copy-on-write friendly garbage collector Hongli Lai
2008-03-03 12:38 ` Daniel DeLorme
2008-03-03 13:11 ` Yukihiro Matsumoto
2008-03-04 11:31   ` Gonzalo Garramuño
2008-03-07 12:04   ` Hongli Lai
2008-03-07 15:20     ` Paul Brannan
2008-03-07 16:22       ` Hongli Lai [this message]
2008-03-07 18:47         ` Joel VanderWerf
2008-03-08  5:34   ` Daniel DeLorme
2008-03-08  7:50     ` Daniel DeLorme
2008-03-08 10:01       ` Daniel DeLorme
2008-03-08 15:39         ` Yukihiro Matsumoto
2008-03-12 17:23       ` Hongli Lai
2008-03-12 17:38         ` Yukihiro Matsumoto
2008-03-13  0:48         ` Daniel DeLorme
2008-03-13 11:04           ` Hongli Lai
2008-03-15 16:15         ` Hongli Lai
2008-03-13 11:18     ` Hongli Lai
2008-03-14  3:20     ` Hongli Lai
2008-03-14  4:44       ` Daniel DeLorme
2008-03-14 11:25         ` Hongli Lai
2008-03-14 12:01           ` Meinrad Recheis
2008-03-14 15:00           ` Daniel Berger
2008-03-14 15:53             ` Hongli Lai
2008-03-14 17:34               ` Joel VanderWerf
2008-03-20 10:59     ` Hongli Lai
2008-03-20 11:55       ` Yukihiro Matsumoto
2008-03-20 12:54         ` Hongli Lai
2008-03-20 14:24           ` Yukihiro Matsumoto
2008-03-20 14:45             ` Hongli Lai
2008-03-20 15:28             ` Joel VanderWerf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47D16BBE.9060005@plan99.net \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).