[erlang-questions] binary optimization

Richard Carlsson <>
Sat Jul 18 13:04:14 CEST 2009


Joel Reymont wrote:
> This doesn't fly either...
> 
> src/flashbot.erl:117: Warning: NOT OPTIMIZED: sub binary is used or
> returned
> 
> handle_info({tcp, _Sock, <<A:32, B:32, C:32, Bin/binary>>}, Where,
> State) ->
>     Delta = timer:now_diff(now(), {A, B, C}),
>     Where(Bin, State#state{latency = Delta});

You missed the important point in Mikael's mail:
"presumably the callee in the tailcall must be known at compile-time,
and must presumably only be called with a delayed sub binary."

In the above, Bin gets passed to Where, which could be anything
as far as the compiler knows. Either you ignore the warning, if you
think that restructuring the code is not worth it here, or you
try to rewrite the whole thing so you get a single main loop with
direct self-recursive tail calls (if that is at all doable).

> src/flashbot.erl:81: Warning: NOT OPTIMIZED: sub binary used by
> erlang:setelement/3
> 
> no_token(<<?TOKEN, _:32, Token/binary>>, State) ->
>     send([?SUBSCRIBE, size(?TOPIC), ?TOPIC],
>          State#state{token = Token},
>          not_subscribed).

Well, it is. Token gets inserted into State. You could probably just
ignore this one.

    /Richard



More information about the erlang-questions mailing list