[erlang-questions] eep: multiple patterns

Sean Hinde sean.hinde@REDACTED
Sun Jun 1 02:19:44 CEST 2008


On 31 May 2008, at 18:21, Darren New wrote:

> Sean Hinde wrote:
>> I had thought that there was an optimisation where if the pattern  
>> was  identical to last time the same receive was entered for that  
>> process  then only newer messages were examined.
>
> I think that's only if you get multiple messages arriving without  
> actually triggering a receive.
>
>> Seems like it could be a useful optimisation in any case :-)
>
> If the guards didn't change and you didn't run any other receive  
> statements, maybe one could detect that. Figuring that out at  
> compile time would seem to be pretty brutal, but noticing which  
> receive statement ran last and keeping a list of all the guard  
> values at run time might work. Probably easier to just say "don't do  
> that."  :-)

If the patterns to be matched in the receive clause are all constants  
or unbound variable the compiler should certainly be able to detect  
that. In this (rather common) case it could generate special code to  
some funky new instructions that save the position in the message  
queue and skip all the unnecessary scanning.

It could also as you say be done at runtime, but with some overhead.  
It seems on the surface to be quite do-able..

This problem (of poor performance with selective receive) seems like  
one of the nastiest (and least well understood ;-) ) gotchas of the  
current runtime. I hope while we consider tweaking the syntax we can  
also find time to optimise the behaviour.

Sean




More information about the erlang-questions mailing list