Skip to content

Optimize function selector by avoiding unnecessary inlining of internal/external receivers #3336

@Gusarich

Description

@Gusarich

Currently, when contracts have both internal and external receivers, our low-level function selector generates two separate IFNOTJMP instructions: one for internal and one for external messages. However, at runtime, only one of these branches can ever be executed, since the incoming message must be either internal or external.

The inefficient compilation occurs because the Fift-assembler decides whether to use JMPREF or inline the code (PUSHCONT + JMP) based on the size of the code block. If the receiver handlers are small enough, the assembler chooses to inline both branches, unnecessarily enlarging the current code cell and causing extra implicit JMPREFs.

Since we know that only one receiver (internal or external) can ever execute, we can optimize this scenario by implementing custom logic in our function selector. This logic would explicitly determine whether to inline or reference each receiver's code block, avoiding unnecessary duplication and implicit jumps.

Metadata

Metadata

Assignees

Labels

kind: gas!Gas consumption and fee-related thingsscope: codegenCode generation, a.k.a. compiler backend (src/generator)

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions