[erlang-questions] binary optimization

Joel Reymont joelr1@REDACTED
Sat Jul 18 13:53:58 CEST 2009


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  
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};
---

Is the compiler telling me that the sub binary is "improperly" used by  
session:subscribe/2, e.g.

subscribe(Ref, Topic) ->
     gen_server:cast(Ref, {subscribe, Topic}).


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};

	Thanks, Joel

---
Mac hacker with a performance bent
http://www.linkedin.com/in/joelreymont



More information about the erlang-questions mailing list