[erlang-questions] fast JSON parser in C

Ulf Wiger <>
Mon Jul 28 00:48:36 CEST 2008


2008/7/28 Richard A. O'Keefe <>:
>
> On 26 Jul 2008, at 3:38 am, Chris Anderson wrote:
>> Joe mentioned not using atoms as keys due to the atom table not being
>> GC'd. The other consideration is making it unambigious between JSON
>> arrays and JSON objects.
>
> Jim Larson pointed out that there are actually THREE alternatives:
> (1) always return labels as binaries.
>     This is always safe, and always clunky.
> (2) always return labels as atoms if you can.
>     This is always nice to use, but is only safe if you
>     can trust the sender to use a small set of labels.
> (3) return labels as atoms if they are EXISTING atoms.
>     This is the possibility that I missed (inexcusably).
>     It means that a module that expects certain labels to be used
>     and mentions those labels will se THOSE labels (and perhaps
>     some others) as atoms, giving you the convenience,
>     but at the same time it won't add anything to the atom table,
>     giving you safety.

But with dynamic code loading, you cannot be sure that the atoms
(presumably created when a given module is loaded) are there
when the message is decoded. If the message has been decoded
before a module matching on the decoded term is loaded, the
labels expected to be atoms may instead be binaries, and it would
be difficult to know which.

BR,
Ulf W



More information about the erlang-questions mailing list