[erlang-questions] pickler combinators + closure fetching from ets vs process registry
Mon Sep 15 16:30:12 CEST 2008
Has anyone benchmarked the speed of fetching a closure from ETS vs a
process-based registry (gen_server + gb_trees)?
I implemented closure-based serialization  based on Andrew
Kennedy's pickle combinators which lets me define both the pickler and
the unpickler for a record like this:
I can then marshall data into an io list with with
pickle(test_start_game(), Data) and get a record back with
The problem is that a "command code" needs to be stored into the
binary to make it possible to unpickle a proper record. This requires
a mapping from record tag to command code and pickler as well as a
mapping from command code to unpickler.
I have these mappings implemented as functions, e.g.
write(R) when is_record(R, bad) ->
read(<<?PP_BAD, Bin/binary>>) ->
The two issues here for me are the long list of write and read clauses
and the closured generated by bad() on every packet read and write.
I'm thinking of storing the tag to pickler and command code mappings
in ETS or a process-based registry. This will both store pickler
closures once and drastically trim the amount of code by getting rid
of the write/read clauses.
Has anyone benchmarked ETS vs a process-based registry for retrieval
of function closures?
P.S. I would appreciate comments or suggestions on how the pickler
code could be further optimized.
More information about the erlang-questions