tact icon indicating copy to clipboard operation
tact copied to clipboard

Optimize cell creation from `Struct.toCell()` compared to `Builder` methods

Open Kaladin13 opened this issue 8 months ago • 1 comments

Struct.toCell() should produce the same gas consumption as manual cell creation with Builder methods. However, when we port logic from manual creation to toCell we lose gas on it. Maybe we should try to optimize it with compiler-level FunC inlining.

We can use wallet-v4 Tact FunC version port in benchmarks as an example for this issue

Here is gist with wallet-v4 implementation using native builder methods

Here is diff, compared with Struct.toCell() version:

Image

Kaladin13 avatar Mar 24 '25 09:03 Kaladin13

Related issue: #2051. Duplicating my comment from here:

For instance, inlining "struct constructors" would save gas but break examples like

get fun create(v: Int): S {
    return S{v3: v.inc(), v2: v.inc(), v1: v.inc()}; // NOTE: Inverted order!
} 

because S's fields are passed to the constructor in the order they appear in the code above, but after inlining the order will be reversed

anton-trunov avatar Apr 08 '25 11:04 anton-trunov