[Top][All Lists]

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

[Chicken-hackers] [PATCH] [CHICKEN 5] Change numerics representations

From: Peter Bex
Subject: [Chicken-hackers] [PATCH] [CHICKEN 5] Change numerics representations
Date: Mon, 8 Aug 2016 22:56:39 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

Hello hackers,

I'm currently busy with a writeup of some of the stuff that went into
the numbers integration (it will take a long while until it's finished,
so don't hold your breath for it!), and I realised that it's a bit
silly to wrap all our extended numbers in a struct.  This just eats up
precious machine words (the struct-type takes up an extra machine word
which we can drop).

This memory usage should in general not be a huge problem, but
unfortunately our inline functions all need to pre-allocate enough
memory for the *worst* case, which is usually a cplxnum that consists
of ratnums in both its real and imaginary parts, and those ratnums in
turn consisting of 2 bignums each.  The actual bignum digit data will be
allocated on-demand in the scratch buffer, but the bignum wrapper, the
ratnums, and the cplxnum "shell" all need to be pre-allocated on the

This is especially noticeable in C_s_a_i_times(), which needs a whopping
40 words pre-allocated.

The attached patches add a custom type for bignums (first patch) and
custom types for ratnums/cplxnums (second patch).  This reduces the
aforementioned C_s_a_i_times() pre-allocation from 40 to 29 words.
Theoretically, this should slow down nursery growth by a quarter(!)
Unfortunately, the benchmark results are not showing any noticeable
difference in run time, though it does show that the number of GCs
and time spent in GC has noticeably diminished; in some benchmarks
the GC time is 5 times faster, but that may just be a fluke...

All in all, I think these changes are worthwhile but for the caveat
that it results in us having NO MORE reserved type tags left!  In
fact, the complete change is only possible because we dropped the
SWIG pointer type; before that we only had two reserved types left.
I don't see an easy way to reclaim type tags elsewhere; we don't have
that many.  Maybe (but only MAYBE) we could get rid of lambda info as
a separate core type.

Now, I also think the original representation of the ratnums and
cplxnums as record types is kind of elegant (making them "not exist"
at the C level, more or less), so I'm a bit on the fence regarding
the second patch.  However, I do think the abstraction of the accessors
as a C macro is a must; I'd be willing to re-do that part as a separate
patch if the whole thing isn't applied.

Making bignums more "core" (first patch) is a great move overall, I
think, so I'd urge you to certainly consider that one.  It also results
in a gain in pre-allocation savings that's as big as the combined
change of ratnums & cplxnums.

Please, discuss!


Attachment: 0001-Change-bignum-representation-to-use-a-custom-type.patch
Description: Text Data

Attachment: 0002-Change-ratnum-and-cplxnum-representation-to-also-use.patch
Description: Text Data

Attachment: signature.asc
Description: Digital signature

reply via email to

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