chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Allow collecting weak pairs in minor GC (was: Re: [PATCH] Add us


From: Peter Bex
Subject: [PATCH] Allow collecting weak pairs in minor GC (was: Re: [PATCH] Add user-facing weak pair API)
Date: Fri, 9 Jun 2023 09:52:58 +0200

On Sat, Jun 03, 2023 at 11:12:40PM +0200, Peter Bex wrote:
> Attached are 5 patches to add the weak pair support.  I've also pushed
> this to the git repo under the "user-facing-weak-pairs" branch.

Attached are two more patches that together wrap up the weak pairs
support.  The first patch gets rid of the hacks that were needed
to get weak pairs working *efficiently* in the original
implementation, by "ignoring" weak pairs in minor GCs and treating them
like regular pairs instead.

Those hacks were needed because initially, weak pairs required
traversing the entire symbol table which would be prohibitively
expensive during minor GC.

The second patch is a minor performance / quality of implementation
improvement that came from an insight I had while enabling minor GC
for weak pairs.  I realised that sometimes, we'd hit the assertion
that a weak pair's car must be a block object in update_weak_pairs().
This got hit because "somehow" the car already contained a #!bwp
object.  Then I realised that's because the same pair gets linked up
in the weak pair chain more than once, and this is more likely to
trigger when minor GCs are allowed to collect weak pairs because
minor GCs are likely to trigger major GCs.  In the first patch
I papered over this by adding a special case for this in
update_weak_pairs(), but it's cleaner to avoid the situation in the
first place.  This is done by resetting the weak pair chain to NULL
when a new GC "mode" is entered.

That works because each forwarded weak pair is guaranteed to be
forwarded again in the new mode, and every non-forwarded weak pair
is *also* guaranteed to be forwarded, if it is live.

I've pushed these two patches to the user-facing-weak-pairs branch
as well.

I ran a benchmark in hopes it would improve performance, but it doesn't
seem to have any effect, which makes sense of course.  The benchmark
programs are all compiled, so their symbols won't be collected, as
the strings for the symbols are all in static ("permanent") storage.
I expect it to have a larger effect on interpreted code and code that
generates a lot of short-lived symbols (e.g. macro-heavy code).

Anyway, remaining TODOs that can be tackled after merging:
- Doing the same for locatives (should greatly affect GC times
  in locative-heavy code, even for minor GCs!)
- Adding line numbers (why we did this in the first place!)

Cheers,
Peter

Attachment: 0001-Enable-minor-collection-of-weak-pairs.patch
Description: Text document

Attachment: 0002-Reset-weak-pair-chain-when-switching-GC-mode.patch
Description: Text document

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]