diff --git a/src/benchmarks/nft/gas.json b/src/benchmarks/nft/gas.json index f079f2c6bf..5e342aefe8 100644 --- a/src/benchmarks/nft/gas.json +++ b/src/benchmarks/nft/gas.json @@ -189,6 +189,16 @@ "deploy nft": "10335", "batch deploy nft": "654266" } + }, + { + "label": "1.6.12 with idiomatic structs handling", + "pr": "https://github.com/tact-lang/tact/pull/3299", + "gas": { + "transfer": "6839", + "get static data": "4336", + "deploy nft": "10335", + "batch deploy nft": "654266" + } } ] } diff --git a/src/benchmarks/nft/size.json b/src/benchmarks/nft/size.json index 7a19fcca05..5dc15d2094 100644 --- a/src/benchmarks/nft/size.json +++ b/src/benchmarks/nft/size.json @@ -199,6 +199,16 @@ "item cells": "10", "item bits": "5217" } + }, + { + "label": "1.6.12 with idiomatic structs handling", + "pr": "https://github.com/tact-lang/tact/pull/3299", + "size": { + "collection cells": "39", + "collection bits": "19204", + "item cells": "10", + "item bits": "5017" + } } ] } diff --git a/src/benchmarks/nft/tact/collection.tact b/src/benchmarks/nft/tact/collection.tact index 57ef972d79..75441ffaf3 100644 --- a/src/benchmarks/nft/tact/collection.tact +++ b/src/benchmarks/nft/tact/collection.tact @@ -2,6 +2,17 @@ import "./constants"; import "./messages"; import "./item"; +struct Content { + collectionContent: Cell; + nftContent: Cell; +} + +struct NFTContent { + tag: Int as uint8; + commonContent: Slice; + individualNFTContent: Cell; +} + contract NFTCollection { owner: Address; nextItemIndex: Int as uint64; // IndexSizeBits = 64 @@ -80,10 +91,9 @@ contract NFTCollection { } get fun get_collection_data(): CollectionData { - let cs: Slice = self.content.beginParse(); return CollectionData { nextItemIndex: self.nextItemIndex, - collectionContent: cs.loadRef(), + collectionContent: Content.fromCell(self.content).collectionContent, owner: self.owner, }; } @@ -97,15 +107,14 @@ contract NFTCollection { return self.royaltyParams; } - get fun get_nft_content(index: Int, individualNFTContent: Cell): Cell { - let cs = self.content.beginParse(); - cs.skipRef(); - let commonContent = cs.loadRef().beginParse(); - return beginCell() - .storeUint(1, 8) // off-chain tag - .storeSlice(commonContent) - .storeRef(individualNFTContent) - .endCell(); + get fun get_nft_content(index: Int, individualNFTContent: Cell): NFTContent { + let commonContent = Content.fromCell(self.content).nftContent.asSlice(); + + return NFTContent { + tag: 1, + commonContent, + individualNFTContent, + }; } } diff --git a/src/benchmarks/nft/tact/item.tact b/src/benchmarks/nft/tact/item.tact index 33fc9eab2e..61e653da04 100644 --- a/src/benchmarks/nft/tact/item.tact +++ b/src/benchmarks/nft/tact/item.tact @@ -17,16 +17,17 @@ contract NFTItem( receive(msg: GetStaticData) { throwUnless(NotInit, self.owner != null); - sendMsg( - sender(), - 0, - ReportStaticData, - msg.queryId, - beginCell() - .storeUint(self.itemIndex, 256) - .storeAddress(self.collectionAddress), - SendRemainingValue, - ); // implementation detail + message(MessageParameters { + bounce: false, + to: sender(), + value: 0, + body: ReportStaticData { + queryId: msg.queryId, + itemIndex: self.itemIndex, + collectionAddress: self.collectionAddress, + }.toCell(), + mode: SendRemainingValue, + }); } receive(msg: Slice) { @@ -67,28 +68,30 @@ contract NFTItem( throwUnless(InvalidFees, restAmount >= 0); if (msg.forwardAmount > 0) { - sendMsg( - msg.newOwner, - msg.forwardAmount, - OwnershipAssigned, - msg.queryId, - beginCell() - .storeAddress(self.owner!!) - .storeSlice(msg.forwardPayload), - SendPayFwdFeesSeparately, - ); + message(MessageParameters { + bounce: false, + to: msg.newOwner, + value: msg.forwardAmount, + body: OwnershipAssigned { + queryId: msg.queryId, + prevOwner: self.owner!!, + forwardPayload: msg.forwardPayload, + }.toCell(), + mode: SendPayFwdFeesSeparately, + }); } if (needResponse) { forceBasechain(msg.responseDestination!!); - sendMsg( - msg.responseDestination!!, - restAmount, - Excesses, - msg.queryId, - beginCell(), - SendPayFwdFeesSeparately, - ); + message(MessageParameters { + bounce: false, + to: msg.responseDestination!!, + value: restAmount, + body: ExcessOut { + queryId: msg.queryId, + }.toCell(), + mode: SendPayFwdFeesSeparately, + }); } self.owner = msg.newOwner; @@ -104,17 +107,3 @@ contract NFTItem( }; } } - -inline fun sendMsg(toAddress: Address, amount: Int, op: Int, queryId: Int, payload: Builder, sendMode: Int) { - message(MessageParameters { - bounce: false, - to: toAddress, - value: amount, - body: beginCell() - .storeUint(op, 32) - .storeUint(queryId, 64) - .storeBuilder(payload) - .endCell(), - mode: sendMode, - }); -} diff --git a/src/benchmarks/nft/tact/messages.tact b/src/benchmarks/nft/tact/messages.tact index eacd7d5b1b..37746478aa 100644 --- a/src/benchmarks/nft/tact/messages.tact +++ b/src/benchmarks/nft/tact/messages.tact @@ -73,3 +73,19 @@ message(0xa8cb00ad) ReportRoyaltyParams { queryId: Int as uint64; params: RoyaltyParams; } + +message(0x8b771735) ReportStaticData { + queryId: Int as uint64; + itemIndex: Int as uint256; + collectionAddress: Address; +} + +message(0x05138d91) OwnershipAssigned { + queryId: Int as uint64; + prevOwner: Address; + forwardPayload: Slice; +} + +message(0xd53276db) ExcessOut { + queryId: Int as uint64; +}