Bytecode size difference when calling storage try_read().unwrap()
instead of read()
#5982
Labels
compiler: ir
IRgen and sway-ir including optimization passes
compiler
General compiler. Should eventually become more specific as the issue is triaged
StorageKey::read()
is internallystorage_api::read().unwrap()
whileStorageKey::try_read()
is juststorage_api::read()
. Thus, one would expect callingstorage.x.read()
andstorage.x.try_read().unwrap()
to produce the same resulting bytecode.This is indeed the case for a single call. But when having multiple calls,
try_read().unwrap()
chains produce noticeable bigger bytecode size.unwrap()
doesn't get inlined and we end up in additional calls tounwrap()
.Even in the simple example below, the bytecode size of calling
multiple_reads()
is ~1700, and when callingmultiple_try_reads()
~2000.In this case, since logically in this case anyhow
read()
should be called, I don't see this as a pressing issue. But it's a good example to take a look at when improving our inlining. Essentially, recognizing chains liketry_read().unwrap()
and inlining them.The text was updated successfully, but these errors were encountered: