[erlang-questions] binary optimization
Mikael Pettersson
mikpe@REDACTED
Sat Jul 18 15:14:38 CEST 2009
On Sat, 18 Jul 2009 12:53:58 +0100, Joel Reymont wrote:
> On Jul 18, 2009, at 12:04 PM, Richard Carlsson wrote:
>
> > 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."
>
>
> What about this one? I'm calling session:subscribe/2 and that's known
> at compile time.
>
> ---
> src/transport.erl:98: Warning: NOT OPTIMIZED: sub binary used by =20
> session:subscribe/2
>
> 98: handle_info({tcp, Sock, <<_:96, ?SUBSCRIBE, Topic/binary>>}, State) ->
> inet:setopts(Sock, [{active, once}]),
> session:subscribe(State#state.session, Topic),
> {noreply, State};
Only the name is known, not the actual code.
> What are the problems with my matching instructions that the following
> warning is referring to?
>
> ---
> src/transport.erl:110: Warning: NOT OPTIMIZED: the binary matching
> instruction that follows in the same function have problems that
> prevent delayed sub binary optimization (probably indicated by INFO
> warnings)
> src/transport.erl:113: Warning: NOT OPTIMIZED: sub binary used by
> topic:publish/2
>
> 110: handle_info({tcp, Sock, <<_:96, ?PUBLISH, Len:32, Bin/binary>>}, State) ->
> inet:setopts(Sock, [{active, once}]),
> Len1 = Len * 8,
> 113: <<Topic:Len1/binary, Msg/binary>> = Bin,
> topic:publish(Topic, Msg),
> {noreply, State};
topic:publish/2 causes Topic and Msg to escape, so they'll need
full-blown term representations. The warning may refer to that, or
it may be that since they are sub-binaries of Bin the compiler gives
up on having Bin as a delayed sub-binary.
More information about the erlang-questions
mailing list