[erlang-questions] Maps branch and disclaimers

Björn-Egil Dahlberg <>
Sat Oct 26 04:52:18 CEST 2013


2013/10/26 Tomas Abrahamsson <>

>
> > Here you go, Maps!
> >
> > I've pushed a Maps branch to Erlang/OTPs repository at GitHub.
>
> Hi, this is cool!
>
> I did some performance experiments with gpb, a google
> protobuf encoder/decoder, in which I had already implemented
> experimental support for maps. It seems map creation is fast!
>
>                     representation of msg
>                     records       maps
>     msg to binary:  27.6 MB/s     22.9 MB/s  (83% of record speed)
>     binary to msg:  27.3 MB/s     29.9 MB/s (110% of record speed)
>
> The figures are number of megabytes processed per second, so
> higher number means faster/better. The "binary to msg" involves
> creating a record or map, with several fields, once for each
> parsed message or sub message. The "msg to binary" uses a match
> for several message fields to assign each field to a variable,
> once for each message or sub message to encode. Included in
> these figures is of course also some binary processing.
>


Oh, nice speed, even without any optimizations. =)


>
>
> I also stumbled upon an what appears to be a compiler error.
> Given this program:
>
>     -module(mapbug).
>     -export([verify_msg/1]).
>
>     verify_msg(Msg) ->
>         v_msg_m1(Msg).
>
>     v_msg_m1(#{f2 := F2}) ->
>         if is_list(F2) -> [v_type_uint32(Elem) || Elem <- F2];
>            true -> ok
>         end,
>         ok;
>     v_msg_m1(_X) ->
>         ok.
>
>     v_type_uint32(_N) ->
>         ok.
>

I believe I found the bug. My attention is a bit split right now so I'm not
completely sure .. watching Vancouver Canucks beat the Blues, and watching
WCS Season 3.

However I think the allocate stack above a fail label which may jump over a
deallocate causes this problem. The following will solve the problem:

diff --git a/lib/compiler/src/beam_block.erl
b/lib/compiler/src/beam_block.erl
index ed660ad..de455f7 100644
--- a/lib/compiler/src/beam_block.erl
+++ b/lib/compiler/src/beam_block.erl
@@ -227,6 +227,7 @@ move_allocates_2(Alloc, [], Acc) ->

 alloc_may_pass({set,_,_,{alloc,_,_}}) -> false;
 alloc_may_pass({set,_,_,{set_tuple_element,_}}) -> false;
+alloc_may_pass({set,_,_,{get_map_element,_,_}}) -> false;
 alloc_may_pass({set,_,_,put_list}) -> false;
 alloc_may_pass({set,_,_,put}) -> false;
 alloc_may_pass({set,_,_,_}) -> true.

I will confer with Björn before pushing anything.

// Björn-Egil


>
> compiling it results in:
>
>     1> c("/path/to/mapbug", []).
>     mapbug: function v_msg_m1/1+17:
>       Internal consistency check failed - please report this bug.
>       Instruction: return
>       Error:       {stack_frame,undecided}:
>
>     error
>
> BRs
> Tomas
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20131026/647c5948/attachment.html>


More information about the erlang-questions mailing list