Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Warning: NOT OPTIMIZED: sub binary is used or returned
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Zabrane Mickael  
View profile  
 More options Aug 6 2012, 12:36 pm
From: Zabrane Mickael <zabra...@gmail.com>
Date: Mon, 6 Aug 2012 18:36:51 +0200
Local: Mon, Aug 6 2012 12:36 pm
Subject: [erlang-questions] Warning: NOT OPTIMIZED: sub binary is used or returned
Hi guys,

I'm communicating with linked-in driver using the following code:

control(Port, Command, Data) ->
    case port_control(Port, Command, Data) of
        <<0, Result/binary>> -> Result;                                           % <- LINE 468  handle a good case
        <<1, Error/binary>>  -> {error, binary_to_term(Error)}    %  <- LINE 469  handle error case
    end.

When compiling, I got this 02 warnings:

$ make
Recompile: src/pimco.erl
src/pimco.erl:468: Warning: NOT OPTIMIZED: sub binary is used or returned
src/pimco.erl469: Warning: NOT OPTIMIZED: sub binary used by erlang:binary_to_term/1
make[2]: Nothing to be done for `all'.

Is there a way to get rid of these warnings and avoid a full binary copies?
Hints?

N.B: my box R14B04/R15B01 on OSX/Linux.

Regards,
Zabrane

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Björn Gustavsson  
View profile  
 More options Aug 7 2012, 2:24 am
From: Björn Gustavsson <bgustavs...@gmail.com>
Date: Tue, 7 Aug 2012 08:24:05 +0200
Local: Tues, Aug 7 2012 2:24 am
Subject: Re: [erlang-questions] Warning: NOT OPTIMIZED: sub binary is used or returned

Yes, you can get rid of the warnings by *not* using the bin_opt_info compiler
option.

No, there is nothing to avoid here. The warning says that
a sub binary is created. A sub binary is small term that
references a part of a binary. Sub binaries is usually an
efficient way to reference just a part of a binary.

So there is *no* copying of the binary data going on in
your example.

The only time you have to worry about sub binaries
being created (and the reason for the optimizations
and compiler warnings) is when sub binaries are
being created repeatedly in a loop, for example in:

b2l(<<H,T/binary>>) ->
   [H|b2l(T)];
b2l(<<>>) ->
   [].

In this case, the compiler will optimize the generated
code to avoid creating a sub binary. Instead of
creating a new sub binary in every iteration of the loop,
a match context will be created once and kept through
the entire loop.

That will be beneficial in two ways:

1) Less garbage will be produced (by not building a
sub binary that will become garbage almost immediately).

2) Matching will be faster when the match context is
already available.

To summarize, don't worry about sub binaries
being created unless it happens repeatedly in a
tight loop.

--
Björn Gustavsson, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Zabrane Mickael  
View profile  
 More options Aug 7 2012, 8:03 am
From: Zabrane Mickael <zabra...@gmail.com>
Date: Tue, 7 Aug 2012 14:03:31 +0200
Local: Tues, Aug 7 2012 8:03 am
Subject: Re: [erlang-questions] Warning: NOT OPTIMIZED: sub binary is used or returned

Hi Björn,

On Aug 7, 2012, at 8:24 AM, Björn Gustavsson wrote:

;-)

> No, there is nothing to avoid here. The warning says that
> a sub binary is created. A sub binary is small term that
> references a part of a binary. Sub binaries is usually an
> efficient way to reference just a part of a binary.

> So there is *no* copying of the binary data going on in
> your example.

Crystal clear.

This version is funny because the compiler now throws only one WARNING instead of two:
$ make
src/pimco.erl:492: Warning: NOT OPTIMIZED: sub binary is used or returned

control(Port, Command, Data) ->
    control(port_control(Port, Command, Data)).

control(<<0, Result/binary>>) ->
    control(Result, true);
control(<<1, Error/binary>>) ->
    control(Error, false).

control(<<Error/binary>>, false) ->  % <--- LINE 492
    {error, binary_to_term(Error)};
control(<<Result/binary>>, true) ->
    Result.

Anyway, thanks for your explanations Björn.

Regards,
Zabrane

_______________________________________________
erlang-questions mailing list
erlang-questi...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »