On Mon, Apr 27, 2009 at 01:42:46PM -0400, Marc Feeley wrote:
I installed OpenBSD 4.5 to determine the source of the problem. It appears that OpenBSD's nanosleep is quite slow and Gambit did not optimize the case where it was sleeping for 0 seconds following a heartbeat interrupt (100 times per second). I have now committed to the repository a patch which optimizes this case. Now the real time and cpu time are almost identical (but note in the results below that OpenBSD is reporting some strange user and system CPU time for the original program, although the sum of these CPU times is correct).
I downloaded the devel sources for 4.4.3 and did a "git fetch" and "git rebase" to the specific commit that fixes the nanosleep problem. The result works precisely as advertised: the times are much improved over the 4.4.2 version I had been running. Thanks very much for taking the time to look into this and optimize for it.
I have also looked into how the performance of your program can be improved. The original program allocates a lot of objects (over 6GB are allocated) that are all very short lived (the amount of live data is well below 1 KB on average). This causes very frequent garbage collections because Gambit's default heap size is really small (200 KB heap size... so the GC is called 30 thousand times!). With a change in heap size, declarations, and algorithm, the program can be sped up by a factor of 30. Here's how the different versions perform with the new patch.
;; Improved sum-of-squares algorithm with declarations (heap size irrelevant):
SOLUTION = 8581147 (time (solution)) 813 ms real time 810 ms cpu time (800 user, 10 system) no collections 2584 bytes allocated 11 minor faults no major faults
This is phenomenal! Clearly I have much to learn about how to optimize code, but with your definitions and some declarations I can get the same thing on my end. Much appreciated!