Concatenating atoms

Matthias Kretschmer <>
Thu Feb 3 22:07:39 CET 2005


Joe Armstrong (AL/EAB) wrote:

>Neat - great idea
>
>I hadn't thought of that
>
>I'm not sure that bigints is a good idea though - it might cause internal
>problems but binaries would be garbed and binary comparisons are presumably
>faster than list comparisions. So the variable Abc on line 23 of my program
>could be represented as {var,23,<<"abc">>}
>
>Yes - I will immediately change my XML parser to this representation :-)
>
>(and a potential compiler bug can be fixed !!!!)
>
>  
>

from a theoretical view the speedup is unimportant (because it is only a 
constant speedup). The speedup given by using atoms is much better: O(1) 
instead of O(n) (if n is the length of the string/binary). The only way 
to achive a performance behaviour of atoms (as they are implemented 
currently in Erlang/OTP) is to use integers of a fixed size (let's they 
of the length of a machine word) or references or something like that. 
This would result in reinventing atom-tables or other mechanisms and 
implementing some sort of garbage collection (or some more complex 
representation that makes use of the built-in garbage collector for 
terms). I think the best solution would be, to solve this problem once. 
In my opinion this is done by extending/changing the runtime system.

Well from a practical view it might be very unimportant, because 
comparing two or three machine words would be sufficient. But if one 
wants to use it for tokens in a compiler, this might not be the case. On 
the other hand looking at some of my code I hardly find many atoms which 
are sharing a common long prefix and have the same length (though don't 
know how atoms are compared, but I could think that first type and 
length is tested and then from left to right). I am just using Erlang 
for small unimportant private projects, so my experience is very limited 
(and programming was nothing more for me besides university). Maybe 
someone with experience (of bigger projects) may enlighten me?

--
Matthias Kretschmer



More information about the erlang-questions mailing list