[erlang-questions] HiPE and large number of string cases

Kostis Sagonas kostis@REDACTED
Mon Jul 2 09:39:50 CEST 2007


Peter Wang wrote:
> Hi,
> 
> I've been writing an Erlang backend for the Mercury compiler.  I've come
> across a problem compiling a particular generated function with HiPE.
> The function simply matches a variable against a string and returns a
> corresponding atom, like this:
> 
>     f(X) ->
> 	case X of
> 	    "option1" -> atom1;
> 	    "option2" -> atom2;
> 	    ...
> 	    _ -> fail
> 	end.
> 
> There are over 500 cases.  Compiling it to bytecode takes a reasonable
> amount of time (~2 secs), but compiling it to native code is unbearably
> slow (over five minutes).  Breaking it into smaller functions does help,
> but it's still not exactly fast (~1 minute).  (These times are at
> optimisation level o1.)

I cannot reproduce your findings with the latest OTP release (R11B-5). 
I've created two such functions, one with 500+1 cases and one with 
1000+1 cases, and the times I get indeed show that there is a non-linear 
component somewhere in the native code compiler, but it is nowhere as 
bad as you describe.

2> timer:tc(hipe, c, [{t,f500,1}]).
{7211870,{ok,{t,f500,1}}}
3> timer:tc(hipe, c, [{t,f1000,1}]).
{21001894,{ok,{t,f1000,1}}}

For me, native code compilation on an x86 running Linux takes about 7.2 
secs for 500 cases and 21 secs for 1000.  With optimization level o1 
these times are smaller.

Which OTP version are you using?  What platform is this?
If you are not using R11B-5, can you try with that and tell us what's 
happening.


Kostis



More information about the erlang-questions mailing list