Optimized single-parent hierarchy calculation
Optimized single-parent hierarchy calculation

In the special (and fairly common) case where a sheep only has one
parent, the hierarchy list can be calculated by consing the sheep onto
the front of the parent's hierarchy list. This tremendously reduces
the cost of some hierarchy calculations.

For example, spawning a linear hierarchy of 8 sheep conses roughly ten
kilobytes of garbage when this optimization is not active. With this
optimization, spawning the same hierarchy leaves no garbage (although
112 bytes are allocated for the actual hierarchy lists).

The optimization was also tested on the following mixed hierarchy:

      C-F
     /   \
  A-B-D   H    (Inheritance flows left-to-right)
     \ \   \
      E-G---I

Spawning this hierarchy without the optimization consed roughly 13 KB
of garbage, whereas with the optimization, it only consed around five
kilobytes.

Note that none of these numbers account for the space taken by the
sheep objects themselves; this is an attempt to estimate the weight of
garbage generated as a side-effect of the calculations.

zkat/sheeple