binary match vs. is_binary in optimization

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

binary match vs. is_binary in optimization

Andreas Schultz
Hi,

Can someone explain why the binary optimization treats a is_binary()
guard different that an binary match?

I the attached test code, I get a:

> test.erl:7: Warning: NOT OPTIMIZED: called function t1/1 does not begin with a suitable binary matching instruction

and a

> test.erl:14: Warning: OPTIMIZED: creation of sub binary delayed

for the second function. IMHO both should be identical, but apparently they are not.

Many thanks,
Andreas

Test code:

-module(test).

-compile([bin_opt_info]).

-export([do/1]).

do(<<Bin/binary>>) ->
    t1(Bin),
    t3(Bin).

t1(Bin) when is_binary(Bin) ->
    test(Bin, []).

t3(<<Bin/binary>>) ->
    test(Bin, []).

test(<<X:4/integer, _/binary>>, _) ->
    X.
--
Dipl.-Inform. Andreas Schultz

email: [hidden email]
phone: +49-391-819099-224

----------------------- enabling your networks ----------------------

Travelping GmbH                     phone:  +49-391-81 90 99 0
Roentgenstr.  13                    fax:    +49-391-81 90 99 299
39108 Magdeburg                     email:  [hidden email]
GERMANY                             web:    http://www.travelping.com

Company Registration: Amtsgericht Stendal        Reg No.:   HRB 10578
Geschaeftsfuehrer: Holger Winkelmann          VAT ID No.: DE236673780
---------------------------------------------------------------------
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: binary match vs. is_binary in optimization

Alex S.
t1 doesn't extract a sub-binary from your binary, so there's nothing to optimize.

2017-08-02 19:35 GMT+03:00 Andreas Schultz <[hidden email]>:
Hi,

Can someone explain why the binary optimization treats a is_binary()
guard different that an binary match?

I the attached test code, I get a:

> test.erl:7: Warning: NOT OPTIMIZED: called function t1/1 does not begin with a suitable binary matching instruction

and a

> test.erl:14: Warning: OPTIMIZED: creation of sub binary delayed

for the second function. IMHO both should be identical, but apparently they are not.

Many thanks,
Andreas

Test code:

-module(test).

-compile([bin_opt_info]).

-export([do/1]).

do(<<Bin/binary>>) ->
    t1(Bin),
    t3(Bin).

t1(Bin) when is_binary(Bin) ->
    test(Bin, []).

t3(<<Bin/binary>>) ->
    test(Bin, []).

test(<<X:4/integer, _/binary>>, _) ->
    X.
--
Dipl.-Inform. Andreas Schultz

email: [hidden email]
phone: +49-391-819099-224

----------------------- enabling your networks ----------------------

Travelping GmbH                     phone:  +49-391-81 90 99 0
Roentgenstr.  13                    fax:    +49-391-81 90 99 299
39108 Magdeburg                     email:  [hidden email]
GERMANY                             web:    http://www.travelping.com

Company Registration: Amtsgericht Stendal        Reg No.:   HRB 10578
Geschaeftsfuehrer: Holger Winkelmann          VAT ID No.: DE236673780
---------------------------------------------------------------------
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions