Version: 0.12.0
Inlining
When compiling a contract in LIGO, declarations will get inlined if they are only used once and pure. Inlining often results in larger contracts and is therefore not aggressively done.
A pure declaration is one that doesn't cause side effects like causing a failure or operation.
In some cases you might want to override the default behaviour of LIGO and force inlining. The declaration still needs to be pure though.
#
Inline attributeTo force inlining you can use the inline attribute.
[@inline] function fst(const p : nat * nat) : nat is p.0;
function main(const p : nat * nat; const s : nat * nat) : list(operation) * (nat * nat) is
((list end : list(operation)), (fst(p.0,p.1), fst(s.1,s.0)))
Now if we measure the difference between inlining and without inlining, using
ligo measure-contract name_of_contract.ligo <entrypoint>
, we see the
following results:
With inlining | 66 bytes |
Without inlining | 170 bytes |
info
Note that these results can change due to ongoing work to optimize output of the LIGO compiler.