[erlang-questions] [eeps] EEP 9

Jay Nelson jay@REDACTED
Wed Mar 5 04:51:51 CET 2008

Taking a quick look at the erlang implementation, I noticed the  

1) The strip_left and strip_right functions are internal, so it would  
be better to put the when is_integer(Sc) clause up a level to check  
it only once (and crash on the caller's function rather than an  
internal one) and maybe add an is_binary clause for the target to be  

2) strip_left and strip_right should be optimized to use skip indexes  
into the binary rather than creating new binaries on each iteration:

     <<_SkipLeft:SkipSize, Sc, _Rest/binary>> = Bin then recurse with  
SkipSize + 1

3) The <<>> clause in strip_left is unnecessary, the pattern match  
for the first character will fail and you can just return the whole  
binary without knowing if it is empty.  A similar fix is probably  
needed for strip_right.  You should see a speed improvement with long  
prefix to strip on either end.

4) duplicate/2 should be a BIF, I would expect it to be used for very  
large binary blocks and you wouldn't want the memory to thrash on  
such a simple instruction.

5) If to_upper and to_lower is really wanted, a BIF will give a much  
faster result.

Take a look at my article on binary BIFs presented at the 2005 ICFP  
conference for other ideas to improve performance of the library.

http://www.duomark.com/erlang/index.html has a link to both the  
article in PDF and the code that obtained the performance numbers  
quoted in the article.


More information about the erlang-questions mailing list