We are building up a dom in memory as part of some XHTML and XUL generation. Found time/memory being spent in append-child which we make heavy use of.
Here are some changes that improve this. The children of a node are stored in a node-list (adjustable vector). Changes involved: -Don't allocate a node list until we actually HAVE children -When allocating a node-list, go ahead and make it 4 elements long (instead of 0) so we don't immediately reallocate, and again. -When vector-push-extending. Let the lisp implementation take care of increasing the size, instead of manually increasing by length 1 every time. Again this reduces constant reallocation. -Use the has-child-nodes function instead of comparing length everywhere.
I attached some test results I got (kind of long), here are the summary lines: seconds | consed | calls | sec/call | name ---------------------------------------------------------- 2.092 | 32,227,920 | 708,718 | | Total ;;OLD 0.859 | 25,507,240 | 691,366 | | Total ;;NEW