How can I eliminate this compilation warning? Warning: BINARY CREATED: binary is used

Hi!
How can I eliminate this compilation warning?
like this:
mgr.erl:285: Warning: BINARY CREATED: binary is used in call to base64:decode/1 which doesn’t support context reuse
% 285| Lev = util:to_integer(base64:decode(Other)),

mgr.erl:285: Warning: NOT OPTIMIZED: binary is used in remote call to base64:decode/1
% 285| Lev = util:to_integer(base64:decode(Other)),

code:

Question about your question : Are you asking how to simply get rid of the warning or how to optimize the code to get rid of the warning?

Sorry, I didn’t make it clear, I want to eliminate the warning by optimizing this code

You can not optimize this code, as far re-using the match context. The compiler is warning that it can not optimize for a match context reuse because of a remote call being made (base64:decode/1), it simply will not work, and that’s how it works, as of now. That is to say match context reuse is limited to local calls. Kindly pinging @garazdawi to validate that statement.

Likewise, you can not inline base64:decode/1 (as of now) to optimize that way, and even if you could, it may not be worth it anyway.

Now, on line 203, you could use decode_to_string/1 since you’re going to make a sub-binary anyway per your match on line 204. You would of course have to benchmark to see if that is worth doing.

From the docs :

Notice that the bin_opt_info is not meant to be a permanent option added to your Makefiles, because all messages that it generates cannot be eliminated. Therefore, passing the option through the environment is in most cases the most practical approach.

Yes.

I can also add that the binary that is created is not a complete copy the Other binary, but a sub binary, which is a small term that references part of the binary returned by base64:decode/1. Creating a sub binary is a very fast operation.

Thanks! I read the documentation and until then I thought there was something wrong with my code. :innocent: :innocent: :innocent: