Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/benchmarks/nft/gas.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
}
10 changes: 10 additions & 0 deletions src/benchmarks/nft/size.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
}
31 changes: 20 additions & 11 deletions src/benchmarks/nft/tact/collection.tact
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
};
}
Expand All @@ -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,
};
}
}

Expand Down
73 changes: 31 additions & 42 deletions src/benchmarks/nft/tact/item.tact
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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,
});
}
16 changes: 16 additions & 0 deletions src/benchmarks/nft/tact/messages.tact
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}