[erlang-questions] Performance on FIFO

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Mon May 24 09:10:43 CEST 2010


On Mon, May 24, 2010 at 8:11 AM, maruthavanan s
<maruthavanan_s@REDACTED> wrote:

> I need to implement a buffer that should hold a fixed length of records say for e.g. 20 with {key,Value} relationship, I expect the key would be integer and value to be list or binary upto
> length of 65536 so that I could transmit then in network.The older records should be removed and newer ones should be appended. I might lookup for Values based on keys. I could see many module where I can implement this like queue, dict, lists, proplists.

Personal preference: I would go with queue first, lugging a count
around for the size of the queue to keep it at 20. It will make you
start quickly and since it has O(1) amortized access (if memory
serves) you will have a fast implementation. I have some code which
essentially does this for a network connection, and it is always the
network connection which is the bottleneck in my case. And I only have
16K binary blocks in the queue. You have 1/4 the number of queue
requests.

You may want to optimize it later. Note that Erlang has a peculiar
performance model. What you think is fast tend not to be and vice
versa[*]

[*] Haskell has an even more peculiar performance model, by the way :)


-- 
J.


More information about the erlang-questions mailing list