Motivated by the discussion about the boot times I dag in the trunk of lost sources and found a piece of code I created long a go for serializing / deserializing (does this word exist?) arbitrary lisp data.<br><br>The code is not complete, for it was a proof of concept -- the real code is somewhere in CVS and I cannot find it right now --, but I managed to plug it in with little effort and the results are interesting.<br>
<br>SI:SERIALIZE is a function that takes an object and produces an (ARRAY (UNSIGNED-BYTE *) (*)) with enough information to reconstruct an EQUAL object. SI:DESERIALIZE does the opposite. The whole code takes very little in C and apart for some big switches to reconstruct the entries in the lisp objects it is pretty simple. Everything is now available in CVS.<br>
<br>The funny thing is that this is an order of magnitude faster than using the reader already for simple objects. The code I use to test it is listed below and the outcome is pretty good.<br><br>It will be worth investigating whether the serializing code remains as efficient when all other data types are introduced.<br>
<br>Juanjo<br><br>;; Using the reader<br>real time : 0.669 secs<br>run time : 0.660 secs<br>gc count : 3 times<br>consed : 2684081 bytes<br><br>;; Using SERIALIZE<br>real time : 0.092 secs<br>run time : 0.091 secs<br>
gc count : 2 times<br>consed : 3183760 bytes<br><br>(eval-when (:compile-toplevel)<br> (defparameter +o+<br> '(1 . #1=(3 "3" . ("445" . #1#))))<br> (defparameter +r1+<br> (let ((*print-circle* t))<br>
(write-to-string +o+)))<br> (defparameter +r2+<br> (si::serialize +o+)))<br><br>(defun foo1 (y)<br> (dotimes (i 100000)<br> (read-from-string y)))<br><br>(defun foo2 (y)<br> (dotimes (i 100000)<br> (si::deserialize y)))<br>
<br>(time (foo1 #.+r1+))<br><br>(time (foo2 #.+r2+))<br><br clear="all"><br>-- <br>Instituto de Física Fundamental, CSIC<br>c/ Serrano, 113b, Madrid 28006 (Spain) <br><a href="http://tream.dreamhosters.com">http://tream.dreamhosters.com</a><br>