Pattern matching vs. ETS lookups
Mon Feb 16 23:16:22 CET 2004
On Mon, 16 Feb 2004 13:26:29 -0500, Serge Aleynikov <serge@REDACTED>
> The main question is if the number of functions is large (~ 65536), is
> it better to implement header/body parsing using hard-coded patterns:
> % Input types: <<FunctionID/8, Body/binary>>
> f1(<<0, 1, Body/binary>>) -> ...;
> f1(<<0, 2, Body/binary>>) -> ...;
> f1(<<255, 255, Body/binary>>) -> ... .
I think this would set a new record for the Erlang compiler,
the current record being held (I think) by the yecc-generated
parser code for the SQL92 grammar. I think both yecc and the
compiler were redesigned to handle that kind of module.
The fun thing about yecc-generated code is that it's basically
only two functions, but e.g. the megaco_text_parser.erl is
~22,000 lines of code. The compiler handles this quite nicely,
so perhaps 65536 function clauses would be possible... nice thing
about Erlang is that you can normally assume that there aren't
many hard limits to worry about, but there may well be in this
case (I have no idea). (: Try and see, and report
the results. It's easy enough to generate a module of that
size for a test.
More information about the erlang-questions