Plans for stricter record semantics in R8

Bjorn Gustavsson bjorn@REDACTED
Mon Oct 16 14:26:45 CEST 2000


In R8, we preliminary plan to stricten the test for valid records
in cases like:

func(R) ->
   A = R#r.field,
   ...
   R#r{field=New}.

In the present implementation, there is no test that R is bound to
a record of the correct size and that the first element is the record
tag. (Retrieving a field is simple a call to element/2 and updating
one field is done through a call to setelement/3.)

However, if you access more than one field at the same time, as in

func(R) ->
   R#r{field1=A,field2=B} = R,
   ...
   R#r{field1=New1,field2=New2}.

the type of R will be checked.

In R8, we plan to always check the record types.

To avoid slowing down record operations, we plan to introduce some
new optimisations:

(1) Using a destructive version of setelement/3 to speed up updates
    of multiple fields. (The update of the first field will be done
    with the normal setelement/3, to avoid both nasty semantic problems
    and nasty crashes in the garbage collector. :-) )

(2) Avoiding multiple type tests on record variables. Typically, the
    same record is typically used several times within a single function.
    In the present implementation, type tests (at least to ensure that it
    is a tuple) will be done every time the record is accessed. It is
    enough to test the type once.

On the average, we except that these optimsations will actually make
record operations faster.

Drawbacks: Sloppy code that depends on the records tests not being done
will stop to work.

/Björn
-- 
Björn Gustavsson            Ericsson Utvecklings AB
bjorn@REDACTED      ÄT2/UAB/F/P
			    BOX 1505
+46 8 727 56 87 	    125 25 Älvsjö



More information about the erlang-questions mailing list