[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Why does the JSON egg map JSON structs to Scheme vec
From: |
Vok Vojwo |
Subject: |
Re: [Chicken-users] Why does the JSON egg map JSON structs to Scheme vectors instead of alists? |
Date: |
Sun, 27 Nov 2011 18:00:25 +0100 |
2011/11/27 Moritz Heidkamp <address@hidden>:
>
> You may be interested in two alternative JSON eggs, namely json-abnf egg
> (GPLed) which represents both JSON objects as tagged lists alists
> (i.e. they have a symbol `object' their car) and arrays as vectors or
> the medea egg (BSD licensed) which uses alists for objects and vectors
> for arrays by default but can be parameterized to use whatever
> representation you prefer.
I think the Medea egg intends to do it the right way. But it seems to be buggy.
And it has a voracious appetite
; loading /usr/local/lib/chicken/6/chicken.import.so ...
; loading /usr/local/lib/chicken/6/data-structures.import.so ...
; loading /usr/local/lib/chicken/6/defstruct.so ...
; loading /usr/local/lib/chicken/6/extras.import.so ...
; loading /usr/local/lib/chicken/6/genturfahi.import.so ...
; loading /usr/local/lib/chicken/6/genturfahi-peg.so ...
; loading /usr/local/lib/chicken/6/genturfahi.so ...
; loading /usr/local/lib/chicken/6/irregex.import.so ...
; loading /usr/local/lib/chicken/6/iset.import.so ...
; loading /usr/local/lib/chicken/6/iset.so ...
; loading /usr/local/lib/chicken/6/lolevel.import.so ...
; loading /usr/local/lib/chicken/6/matchable.import.so ...
; loading /usr/local/lib/chicken/6/matchable.so ...
; loading /usr/local/lib/chicken/6/medea.import.so ...
; loading /usr/local/lib/chicken/6/medea.so ...
; loading /usr/local/lib/chicken/6/ports.import.so ...
; loading /usr/local/lib/chicken/6/posix.import.so ...
; loading /usr/local/lib/chicken/6/regex.import.so ...
; loading /usr/local/lib/chicken/6/regex.so ...
; loading /usr/local/lib/chicken/6/sandbox.so ...
; loading /usr/local/lib/chicken/6/scheme.import.so ...
; loading /usr/local/lib/chicken/6/srfi-13.import.so ...
; loading /usr/local/lib/chicken/6/srfi-14.import.so ...
; loading /usr/local/lib/chicken/6/srfi-18.import.so ...
; loading /usr/local/lib/chicken/6/srfi-1.import.so ...
; loading /usr/local/lib/chicken/6/srfi-4.import.so ...
; loading /usr/local/lib/chicken/6/srfi-69.import.so ...
; loading /usr/local/lib/chicken/6/unicode-char-sets.import.so ...
; loading /usr/local/lib/chicken/6/unicode-char-sets.so ...
; loading /usr/local/lib/chicken/6/utf8-case-map.import.so ...
; loading /usr/local/lib/chicken/6/utf8-case-map.so ...
; loading /usr/local/lib/chicken/6/utf8.import.so ...
; loading /usr/local/lib/chicken/6/utf8-lolevel.import.so ...
; loading /usr/local/lib/chicken/6/utf8-lolevel.so ...
; loading /usr/local/lib/chicken/6/utf8.so ...
; loading /usr/local/lib/chicken/6/utf8-srfi-13.import.so ...
; loading /usr/local/lib/chicken/6/utf8-srfi-13.so ...
; loading /usr/local/lib/chicken/6/utf8-srfi-14.import.so ...
; loading /usr/local/lib/chicken/6/utf8-srfi-14.so ...
; loading /usr/local/lib/chicken/6/vector-lib.import.so ...
; loading /usr/local/lib/chicken/6/vector-lib.so ...
compared to the Json egg:
; loading /usr/local/lib/chicken/6/json.import.so ...
; loading /usr/local/lib/chicken/6/scheme.import.so ...
; loading /usr/local/lib/chicken/6/chicken.import.so ...
; loading /usr/local/lib/chicken/6/ports.import.so ...
; loading /usr/local/lib/chicken/6/srfi-1.import.so ...
; loading /usr/local/lib/chicken/6/srfi-69.import.so ...
; loading /usr/local/lib/chicken/6/packrat.import.so ...
; loading /usr/local/lib/chicken/6/json.so ...
; loading /usr/local/lib/chicken/6/packrat.so ...
I am testing with Googles developer calendar:
(use http-client)
(define json
(with-input-from-request
"http://www.google.com/calendar/feeds/address@hidden/public/full?alt=json"
#f read-string))
Medea fails to parse the data:
(use medea)
(read-json json) ;; => #f
Json works but it is quite slow:
(use json)
(time (begin (json-read (open-input-string json)) (if #f #f)))
0.228s CPU time, 0.12s GC time (major), 135063 mutations, 6/1835 GCs
(major/minor)
0.236s CPU time, 0.128s GC time (major), 135045 mutations, 6/1835 GCs
(major/minor)
compared to Json-abnf:
(use json-abnf)
(time (begin (parser json) (if #f #f)))
0.04s CPU time, 2380 mutations, 0/782 GCs (major/minor)
0.04s CPU time, 2398 mutations, 0/782 GCs (major/minor)
I am completely astonished that the performance difference is more
than 500%. Is this the typical packrat memorization penalty?
So in the end I have
- Medea which has the most useful data representation but does not work.
- Json which need the fewest number of modules, but which is slow and
produces strange pairs of vectors.
- Json-abnf which is the fastest but produces annoying object tags and
can not read from ports.
If it is possible to get rid of the object tags Json-abnf seems to be
the best choice right now.