diff --git a/src/stdlib/stdlib/std/internal/cells.tact b/src/stdlib/stdlib/std/internal/cells.tact index 799888e6c..f6c33dab1 100644 --- a/src/stdlib/stdlib/std/internal/cells.tact +++ b/src/stdlib/stdlib/std/internal/cells.tact @@ -467,12 +467,12 @@ inline extends fun asCell(self: Builder): Cell { return self.endCell(); } -inline fun emptyCell(): Cell { - return beginCell().endCell(); +asm fun emptyCell(): Cell { + PUSHREF // Pure Fift: "" turns it into a cell at compile time } -inline fun emptySlice(): Slice { - return emptyCell().asSlice(); +asm fun emptySlice(): Slice { + b{} PUSHSLICE } /// Struct for holding values computed by the `Cell.computeDataSize()` and `Slice.computeDataSize()` extension functions. Available since Tact 1.6.0. diff --git a/src/test/benchmarks/__snapshots__/benchmarks.spec.ts.snap b/src/test/benchmarks/__snapshots__/benchmarks.spec.ts.snap index ca8e41438..f4e98e9a6 100644 --- a/src/test/benchmarks/__snapshots__/benchmarks.spec.ts.snap +++ b/src/test/benchmarks/__snapshots__/benchmarks.spec.ts.snap @@ -1,9 +1,13 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`benchmarks benchmark functions: code size 1`] = `211`; +exports[`benchmarks benchmark cells creation: gas used emptyCell 1`] = `931n`; -exports[`benchmarks benchmark functions: gas used 1`] = `2769n`; +exports[`benchmarks benchmark cells creation: gas used emptySlice 1`] = `1035n`; -exports[`benchmarks benchmark readFwdFee: code size 1`] = `157`; +exports[`benchmarks benchmark functions: code size 1`] = `227`; -exports[`benchmarks benchmark readFwdFee: gas used 1`] = `2799n`; +exports[`benchmarks benchmark functions: gas used 1`] = `2869n`; + +exports[`benchmarks benchmark readFwdFee: code size 1`] = `173`; + +exports[`benchmarks benchmark readFwdFee: gas used 1`] = `2899n`; diff --git a/src/test/benchmarks/benchmarks.spec.ts b/src/test/benchmarks/benchmarks.spec.ts index 7e96881be..755a25959 100644 --- a/src/test/benchmarks/benchmarks.spec.ts +++ b/src/test/benchmarks/benchmarks.spec.ts @@ -16,6 +16,7 @@ import { Sha256Big } from "./contracts/output/benchmark_sha256_big_Sha256Big"; import { Sha256AsSlice } from "./contracts/output/benchmark_sha256_as_slice_Sha256AsSlice"; import { Forward } from "./contracts/output/forward_Forward"; import "@ton/test-utils"; +import { cellsCreation } from "./contracts/output/cells_cellsCreation"; import { getUsedGas } from "./util"; function measureGas(txs: BlockchainTransaction[]) { @@ -164,4 +165,22 @@ describe("benchmarks", () => { await hashStringAsSLice(sha256AsSlice, "hello world".repeat(10)), ).toEqual(2516n); }); + it("benchmark cells creation", async () => { + const testContract = blockchain.openContract( + await cellsCreation.fromInit(), + ); + await testContract.send( + treasure.getSender(), + { value: toNano(1) }, + beginCell().asSlice(), + ); + const gasUsed1 = ( + await blockchain.runGetMethod(testContract.address, "getEmptyCell") + ).gasUsed; + expect(gasUsed1).toMatchSnapshot("gas used emptyCell"); + const gasUsed2 = ( + await blockchain.runGetMethod(testContract.address, "getEmptySlice") + ).gasUsed; + expect(gasUsed2).toMatchSnapshot("gas used emptySlice"); + }); }); diff --git a/src/test/benchmarks/contracts/cells.tact b/src/test/benchmarks/contracts/cells.tact new file mode 100644 index 000000000..7adb3e325 --- /dev/null +++ b/src/test/benchmarks/contracts/cells.tact @@ -0,0 +1,11 @@ +contract cellsCreation { + receive(msg: Slice) { + + } + get fun getEmptyCell(): Cell { + return emptyCell(); + } + get fun getEmptySlice(): Slice { + return emptySlice(); + } +}