Skip to content

Commit

Permalink
fix(world): inline debug constants [L-11] (#1976)
Browse files Browse the repository at this point in the history
Co-authored-by: Fraser Scott <fraserdscott@gmail.com>
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
  • Loading branch information
3 people committed Jan 12, 2024
1 parent e6c03a8 commit d00c4a9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-wombats-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world": patch
---

Removed `ROOT_NAMESPACE_STRING` and `ROOT_NAME_STRING` exports in favor of inlining these constants, to avoid reuse as they're meant for internal error messages and debugging.
44 changes: 22 additions & 22 deletions packages/world-modules/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,85 @@
"file": "test/ERC20.t.sol",
"test": "testApprove",
"name": "approve",
"gasUsed": 114366
"gasUsed": 114369
},
{
"file": "test/ERC20.t.sol",
"test": "testBurn",
"name": "burn",
"gasUsed": 75931
"gasUsed": 75937
},
{
"file": "test/ERC20.t.sol",
"test": "testMint",
"name": "mint",
"gasUsed": 161770
"gasUsed": 161776
},
{
"file": "test/ERC20.t.sol",
"test": "testTransfer",
"name": "transfer",
"gasUsed": 93016
"gasUsed": 93022
},
{
"file": "test/ERC20.t.sol",
"test": "testTransferFrom",
"name": "transferFrom",
"gasUsed": 130355
"gasUsed": 130367
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveAllGas",
"name": "setApprovalForAll",
"gasUsed": 113993
"gasUsed": 113996
},
{
"file": "test/ERC721.t.sol",
"test": "testApproveGas",
"name": "approve",
"gasUsed": 87999
"gasUsed": 88005
},
{
"file": "test/ERC721.t.sol",
"test": "testBurnGas",
"name": "burn",
"gasUsed": 101937
"gasUsed": 101949
},
{
"file": "test/ERC721.t.sol",
"test": "testMintGas",
"name": "mint",
"gasUsed": 169501
"gasUsed": 169510
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeMintToEOAGas",
"name": "safeMint",
"gasUsed": 169772
"gasUsed": 169781
},
{
"file": "test/ERC721.t.sol",
"test": "testSafeTransferFromToEOAGas",
"name": "safeTransferFrom",
"gasUsed": 143774
"gasUsed": 143789
},
{
"file": "test/ERC721.t.sol",
"test": "testTransferFromGas",
"name": "transferFrom",
"gasUsed": 136934
"gasUsed": 136946
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
"name": "install keys in table module",
"gasUsed": 1413357
"gasUsed": 1413360
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "install keys in table module",
"gasUsed": 1413357
"gasUsed": 1413360
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -93,13 +93,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallSingleton",
"name": "install keys in table module",
"gasUsed": 1413357
"gasUsed": 1413360
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "install keys in table module",
"gasUsed": 1413357
"gasUsed": 1413360
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -117,7 +117,7 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "install keys in table module",
"gasUsed": 1413357
"gasUsed": 1413360
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -135,7 +135,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testGetKeysWithValueGas",
"name": "install keys with value module",
"gasUsed": 668168
"gasUsed": 668171
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -153,7 +153,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "install keys with value module",
"gasUsed": 668168
"gasUsed": 668171
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -165,7 +165,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "install keys with value module",
"gasUsed": 668168
"gasUsed": 668171
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -183,7 +183,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "install keys with value module",
"gasUsed": 668168
"gasUsed": 668171
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand Down Expand Up @@ -315,7 +315,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 663827
"gasUsed": 663830
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand Down
8 changes: 7 additions & 1 deletion packages/world/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"file": "test/World.t.sol",
"test": "testRegisterRootFunctionSelector",
"name": "Register a root function selector",
"gasUsed": 80462
"gasUsed": 80457
},
{
"file": "test/World.t.sol",
Expand Down Expand Up @@ -172,5 +172,11 @@
"test": "testGetType",
"name": "get type from a resource ID",
"gasUsed": 4
},
{
"file": "test/WorldResourceId.t.sol",
"test": "testToString",
"name": "convert resource ID to string",
"gasUsed": 3313
}
]
7 changes: 2 additions & 5 deletions packages/world/src/WorldResourceId.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { RESOURCE_NAMESPACE, MASK_RESOURCE_NAMESPACE } from "./worldResourceType
uint256 constant NAMESPACE_BITS = 14 * 8; // 14 bytes * 8 bits per byte
uint256 constant NAME_BITS = 16 * 8; // 16 bytes * 8 bits per byte

bytes16 constant ROOT_NAMESPACE_STRING = bytes16("ROOT_NAMESPACE");
bytes16 constant ROOT_NAME_STRING = bytes16("ROOT_NAME");

bytes32 constant NAMESPACE_MASK = bytes32(~bytes14("")) >> (TYPE_BITS);

/**
Expand Down Expand Up @@ -102,9 +99,9 @@ library WorldResourceIdInstance {
abi.encodePacked(
resourceType,
":",
resourceNamespace == ROOT_NAMESPACE ? ROOT_NAMESPACE_STRING : resourceNamespace,
resourceNamespace == ROOT_NAMESPACE ? "<root>" : WorldResourceIdLib.toTrimmedString(resourceNamespace),
":",
resourceName == ROOT_NAME ? ROOT_NAME_STRING : resourceName
resourceName == ROOT_NAME ? "<root>" : WorldResourceIdLib.toTrimmedString(resourceName)
)
);
}
Expand Down
14 changes: 14 additions & 0 deletions packages/world/test/WorldResourceId.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ contract WorldResourceIdTest is Test, GasReporter {
assertEq(ResourceId.unwrap(namespaceId), ResourceId.unwrap(WorldResourceIdLib.encodeNamespace("namespace")));
}

function testToString() public {
ResourceId resourceId = WorldResourceIdLib.encode({
typeId: RESOURCE_SYSTEM,
namespace: "namespace",
name: "name"
});

startGasReport("convert resource ID to string");
string memory resourceIdString = resourceId.toString();
endGasReport();

assertEq(resourceIdString, "sy:namespace:name");
}

function testGetType() public {
ResourceId resourceId = WorldResourceIdLib.encode({
typeId: RESOURCE_SYSTEM,
Expand Down

0 comments on commit d00c4a9

Please sign in to comment.