@Alfred,
I wrote a small bench:
https://gist.github.com/1342872
Results MacBook Pro + Lion + node 0.6.0:
JSURL.stringify: 1617
JSON.stringify: 152
JSON.stringify + URL encode: 1731
JSURL.parse: 985
JSON.parse: 134
URL decode + JSON.parse: 579
JSON is obviously much faster (not a big surprise).
But JSON + URI encode/decode is a fairer comparison. Here JSURL does a
bit better on stringify but is slower on parse.
@Peter
Thanks for the pointer. I looked at Rison (did not know about it). It
addresses the same problem. It find it a bit complex, though. A few
remarks:
1) Rison must be combined with a percent encoding/decoding pass. JSURL
does not because its output only contains characters that don't need
URL escaping.
2) Rison uses comma and colon. These characters are encoded by
encodeURIComponent. So you only get the advertised compression/
readability if you encode with encodeURI. Seems problematic because
the typical use case is to encode query parameter values and the
recommended method in this case is encodeURIComponent.
3) The idea of sorting keys to normalize and improve caching is
interesting (I hadn't thought about that). But it introduces overhead
and, as most URLs will be generated by programs, there is a good
chance that keys will come in a fixed order most of the time.
Bruno
On Nov 6, 3:42 am, Peter Lejeck <
peter.lej...@gmail.com> wrote:
> What about something like Rison?
http://mjtemplate.org/examples/rison.html