[Ecls-list] Object serialization

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Sun Jun 6 14:32:46 UTC 2010

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.

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.

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.

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.

It will be worth investigating whether the serializing code remains as
efficient when all other data types are introduced.


;; Using the reader
real time : 0.669 secs
run time  : 0.660 secs
gc count  : 3 times
consed    : 2684081 bytes

real time : 0.092 secs
run time  : 0.091 secs
gc count  : 2 times
consed    : 3183760 bytes

(eval-when (:compile-toplevel)
  (defparameter +o+
    '(1 . #1=(3 "3" . ("445" . #1#))))
  (defparameter +r1+
    (let ((*print-circle* t))
      (write-to-string +o+)))
  (defparameter +r2+
    (si::serialize +o+)))

(defun foo1 (y)
  (dotimes (i 100000)
    (read-from-string y)))

(defun foo2 (y)
  (dotimes (i 100000)
    (si::deserialize y)))

(time (foo1 #.+r1+))

(time (foo2 #.+r2+))

Instituto de Física Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20100606/aeea701f/attachment.html>

More information about the ecl-devel mailing list