The Fool on the Hill

The Fool on the Hill

Freezer sizing

By Simon Brooke || 30 August 2013

(Image) As I prepare to send the pigs to slaughter, one important issue is how big a freezer to buy.

My estimate of my pigs' live weight, using a well known estimating technique, is about 90 Kg each. Boned out dead weight is likely to be about 66% of that, so say 120 Kg. Of course I shan't keep all that, I'll sell some and give some away; and I shan't freeze all I keep. But given that I won't know how much I'll sell until I sell it, I need to reckon on being able to store 100 Kg of frozen meat.

Flesh just about floats in water; it's within 10% the same density. So a kilogram of meat is about a litre of meat, give or take not very much. But, the packing density will not be perfect; there will inevitably be gaps. Let's say between fudge factors and packing density, I'll need to have space for at least 120 litres.

Continue reading →


Reference counting, and the garbage collection of equal sized objects

By Simon Brooke || 25 August 2013

A LEGO model of a grabage collector

Yes, I'm still banging on about ideas provoked by the Wing, White and Singer paper, as presented at Mostly Functional. Brief summary: on Friday I posted an essay on the possible use of cons-space as an optimisation for the JVM memory allocator, for use specifically with functional languages (I'm thinking mainly of Clojure, but it has implications for other things such as Armed Bear Common Lisp, and possibly also Scala). Yesterday, I wrote about maintaining a separate heap for immutable objects, as another optimisation. Today, I'm going to write about reference counting, and where it fits in the mix.

The HotSpot JVM uses a tunable generational garbage collector, as detailed here. Generational garbage collectors are a development of the classic mark-and-sweep garbage collector that was used in early LISP implementations from about 1962.

Continue reading →


Images of rape

By Simon Brooke || 25 August 2013

Alessandro Allori's particularly troubling image of Susanna and The Elders Today has been a day to remember Martin Niemöller. He first cropped up for me this morning, when I saw a news article about the Greek authorities rounding up and interning transexual people as 'undesirables'. But it bit into something I have been thinking for a while about Scotland's (and soon England's, too) repressive and ill thought out legislation on extreme pornography, and especially images of (simulated) rape.

I don't make images of simulated rape. I'm not aware of having ever seen images of 'simulated rape' — and I don't believe I'd know one if I saw one. This law is not against me.

But I do write stories about the ambiguities of sexual morality, and some of my stories touch on ambiguities about consent. In my novel, Harem, there is a rape scene, although I'd claim it's intentionally not eroticised. But what can be done to the visual image can be done even more to the written narrative, because while a static image literally cannot portray consent or the absence of consent, a narrative can (and, if it's taking the matter seriously, must). So this law may not be against me, but it is on a slippery slope, and if the moral Taleban are allowed to get away with this one, the next law may well be about me.

Continue reading →


The immutable pool: more on optimising memory management for functional languages

By Simon Brooke || 24 August 2013

The Reverend Robert Walker Skating on Duddingston Loch

Further to yesterday's note on optimising the Java Runtime Environment's memory allocator for the code generated by functional language compilers, I've been reading up on the memory allocator in the OpenJDK Java platform implementation.

First, a note about nomenclature. To my mind the 'Java Virtual Machine' is simply a processor which processes instruction codes — as it were, something in the same category as an ARM 6 or an Intel 80486, except implemented in software. To me it's clear that memory management is not 'part of' that device, it's a low level library expected to be available as part of the runtime environment. However, the writers of the HotSpot VM documentation don't see it that way. To them, the memory allocator is part of the virtual machine, not part of the runtime environment, and as I'm playing with their ball I shall try in what follows to stick to their preferred nomenclature.

Continue reading →


Functional languages, memory management, and modern language runtimes

By Simon Brooke || 23 August 2013

At the Mostly Functional workshop at the Turing Festival in Edinburgh yesterday, I attended a very interesting presentation on the performance of compilers of functional languages for the JVM by Wing Hang Li and Jeremy Singer. The whole talk was interesting, but some of the graphs were electrifying.

What Wing had done was analyse the emitted code size of methods emitted by the different compilers (Scala, Clojure, Jython and JRuby). These showed that the code emitted by these compilers was systematically different — very different — from code emitted by the Java compiler. Typically, they generated smaller code units ('methods', in the terminology of the presentation) — this especially true of Scala — and made much more use of stack. But of more interest to me was this: "We examine the distribution of object sizes, weighted by their dynamic allocation frequency. The size of java.lang.Object is 16 bytes for the JVM we use. The boxplots in Figure 6 show that the object size for most non-Java JVM languages is dominated by only one or two sizes. This can be seen from the median object size in the unfiltered JRuby and Jython boxplots and the filtered Clojure and Scala boxplots. However, the median object size for Java varies between 24 to 48 bytes. By comparing the unfiltered and filtered boxplots, we see that Clojure and Scala use smaller objects more frequently than Java." This is kind of what one would expect. Functional languages should (hopefully) encourage programmers to use smaller units of code than imperative languages; and, because functional programming paradigms make much more use of recursion than typical imperative paradigms, you'd expect to see more use of stack. But more significantly, a great deal of the memory allocation is likely to be small fixed size objects (CONS cells, and other things like e.g. ints and doubles which will fit into the memory footprint of a CONS cell), and that furthermore these small objects are likely to be allocated and deallocated much more frequently than larger objects. And this takes me right back into ideas about the design of LISP runtimes that I was interested in twenty five years ago.

Given this pattern of a rapid churn of small fixed-size objects a naive heap allocator will tend to fragment the heap, as small but still-live objects become sparsely scattered through heap space, ultimately requiring a full mark-and-sweep before larger objects can be allocated. Now I'm certain that the Java heap allocator is anything but naive, but it's unlikely to be optimised for large numbers of rapidly allocated and deallocated equal sized objects.

Continue reading →


This site does not track you; it puts no cookies on your browser. Consequently you don't have to click through any annoying click-throughs, and your privacy rights are not affected.

Wouldn't it be nice if more sites were like this?

About Cookies