You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The store_slice function within the stdlib.fc file of the TON Blockchain has been identified as an area for potential optimization. The current implementation leads to unnecessary gas consumption due to the order of operations in the TON Virtual Machine (TVM). This document outlines the proposed changes, the expected benefits, and the steps to contribute this optimization back to the project.
Current Issue:
The existing store_slice function is implemented as follows in C:
builderstore_slice(builderb, slices) "STSLICER";
This results in the following assembly instructions:
execute SWAPexecute STSLICER
The gas consumption for this sequence is 44 units (18 for SWAP + 26 for STSLICER).
Proposed Optimization:
By rewriting the function directly in assembly, we can achieve the desired operation order without the need for an additional SWAP operation:
This change results in a more efficient single assembly instruction:
execute STSLICE
With this optimization, the gas consumption is reduced to just 18 units, which is a significant improvement over the original implementation.
Benefits of the Optimization:
Reduced Gas Consumption: The most immediate benefit is the reduction in gas consumption from 44 units to 18 units. This can lead to cost savings for users interacting with smart contracts on the TON Blockchain, as they will require less gas to execute the store_slice operation.
Improved Efficiency: The optimized function is more efficient in terms of both gas usage and execution speed, as it eliminates the unnecessary SWAP operation.
Simplified Assembly: The assembly code is simplified, which can make it easier to understand and maintain.
The text was updated successfully, but these errors were encountered:
Overview:
The
store_slice
function within thestdlib.fc
file of the TON Blockchain has been identified as an area for potential optimization. The current implementation leads to unnecessary gas consumption due to the order of operations in the TON Virtual Machine (TVM). This document outlines the proposed changes, the expected benefits, and the steps to contribute this optimization back to the project.Current Issue:
The existing
store_slice
function is implemented as follows in C:This results in the following assembly instructions:
The gas consumption for this sequence is 44 units (18 for SWAP + 26 for STSLICER).
Proposed Optimization:
By rewriting the function directly in assembly, we can achieve the desired operation order without the need for an additional SWAP operation:
This change results in a more efficient single assembly instruction:
execute STSLICE
With this optimization, the gas consumption is reduced to just 18 units, which is a significant improvement over the original implementation.
Benefits of the Optimization:
Reduced Gas Consumption: The most immediate benefit is the reduction in gas consumption from 44 units to 18 units. This can lead to cost savings for users interacting with smart contracts on the TON Blockchain, as they will require less gas to execute the
store_slice
operation.Improved Efficiency: The optimized function is more efficient in terms of both gas usage and execution speed, as it eliminates the unnecessary SWAP operation.
Simplified Assembly: The assembly code is simplified, which can make it easier to understand and maintain.
The text was updated successfully, but these errors were encountered: