Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(world): add module gas reports for setting many keys #771

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
110 changes: 109 additions & 1 deletion packages/world/gas-report.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,58 @@
[
{
"source": "test/KeysInTableModule.t.sol",
"name": "install keys in table module",
"functionCall": "world.installRootModule(keysInTableModule, abi.encode(sourceTableId))",
"gasUsed": 1032425
},
{
"source": "test/KeysInTableModule.t.sol",
"name": "Setting the last of 10 keys",
"functionCall": "world.setRecord(namespace, sourceFile, lastKey, abi.encodePacked(value))",
"gasUsed": 184984
},
{
"source": "test/KeysInTableModule.t.sol",
"name": "Get list of 10 keys with a given value",
"functionCall": "bytes32[][] memory keyTuples = getKeysInTable(world, sourceTableId)",
"gasUsed": 17032
},
{
"source": "test/KeysInTableModule.t.sol",
"name": "install keys in table module",
"functionCall": "world.installRootModule(keysInTableModule, abi.encode(sourceTableId))",
"gasUsed": 1032425
},
{
"source": "test/KeysInTableModule.t.sol",
"name": "Setting the last of 100 keys",
"functionCall": "world.setRecord(namespace, sourceFile, lastKey, abi.encodePacked(value))",
"gasUsed": 243107
},
{
"source": "test/KeysInTableModule.t.sol",
"name": "Get list of 100 keys with a given value",
"functionCall": "bytes32[][] memory keyTuples = getKeysInTable(world, sourceTableId)",
"gasUsed": 106170
},
{
"source": "test/KeysInTableModule.t.sol",
"name": "install keys in table module",
"functionCall": "world.installRootModule(keysInTableModule, abi.encode(sourceTableId))",
"gasUsed": 1032425
},
{
"source": "test/KeysInTableModule.t.sol",
"name": "Setting the last of 1000 keys",
"functionCall": "world.setRecord(namespace, sourceFile, lastKey, abi.encodePacked(value))",
"gasUsed": 841087
},
{
"source": "test/KeysInTableModule.t.sol",
"name": "Get list of 1000 keys with a given value",
"functionCall": "bytes32[][] memory keyTuples = getKeysInTable(world, sourceTableId)",
"gasUsed": 1150690
},
{
"source": "test/KeysInTableModule.t.sol",
"name": "install keys in table module",
Expand Down Expand Up @@ -39,7 +93,61 @@
"source": "test/KeysWithValueModule.t.sol",
"name": "Get list of keys with a given value",
"functionCall": "bytes32[] memory keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value1))",
"gasUsed": 7658
"gasUsed": 7699
},
{
"source": "test/KeysWithValueModule.t.sol",
"name": "install keys with value module",
"functionCall": "world.installRootModule(keysWithValueModule, abi.encode(sourceTableId))",
"gasUsed": 609250
},
{
"source": "test/KeysWithValueModule.t.sol",
"name": "Setting the last of 10 keys",
"functionCall": "world.setRecord(namespace, sourceName, lastKey, abi.encodePacked(value))",
"gasUsed": 134835
},
{
"source": "test/KeysWithValueModule.t.sol",
"name": "Get list of 10 keys with a given value",
"functionCall": "bytes32[] memory keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value))",
"gasUsed": 12160
},
{
"source": "test/KeysWithValueModule.t.sol",
"name": "install keys with value module",
"functionCall": "world.installRootModule(keysWithValueModule, abi.encode(sourceTableId))",
"gasUsed": 609250
},
{
"source": "test/KeysWithValueModule.t.sol",
"name": "Setting the last of 100 keys",
"functionCall": "world.setRecord(namespace, sourceName, lastKey, abi.encodePacked(value))",
"gasUsed": 192958
},
{
"source": "test/KeysWithValueModule.t.sol",
"name": "Get list of 100 keys with a given value",
"functionCall": "bytes32[] memory keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value))",
"gasUsed": 57149
},
{
"source": "test/KeysWithValueModule.t.sol",
"name": "install keys with value module",
"functionCall": "world.installRootModule(keysWithValueModule, abi.encode(sourceTableId))",
"gasUsed": 609250
},
{
"source": "test/KeysWithValueModule.t.sol",
"name": "Setting the last of 1000 keys",
"functionCall": "world.setRecord(namespace, sourceName, lastKey, abi.encodePacked(value))",
"gasUsed": 790938
},
{
"source": "test/KeysWithValueModule.t.sol",
"name": "Get list of 1000 keys with a given value",
"functionCall": "bytes32[] memory keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value))",
"gasUsed": 571426
},
{
"source": "test/KeysWithValueModule.t.sol",
Expand Down
75 changes: 75 additions & 0 deletions packages/world/test/KeysInTableModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,79 @@ contract KeysInTableModuleTest is Test {
// Assert that the key tuple is in the source table
assertTrue(hasKey(world, sourceTableId, keyTuple));
}

function testGetKeysWithValueMany10() public {
_installKeysInTableModule();

uint256 AMOUNT = 10;
uint256 value = 1;

bytes32[] memory lastKey = new bytes32[](1);
lastKey[0] = bytes32(uint256(AMOUNT - 1));

for (uint256 i; i < AMOUNT - 1; i++) {
bytes32[] memory key = new bytes32[](1);
key[0] = bytes32(i);
world.setRecord(namespace, sourceFile, key, abi.encodePacked(value));
}

// !gasreport Setting the last of 10 keys
world.setRecord(namespace, sourceFile, lastKey, abi.encodePacked(value));

// !gasreport Get list of 10 keys with a given value
bytes32[][] memory keyTuples = getKeysInTable(world, sourceTableId);

// Assert that the list is correct
assertEq(keyTuples.length, AMOUNT);
}

function testGetKeysWithValueMany100() public {
_installKeysInTableModule();

uint256 AMOUNT = 100;
uint256 value = 1;

bytes32[] memory lastKey = new bytes32[](1);
lastKey[0] = bytes32(uint256(AMOUNT - 1));

for (uint256 i; i < AMOUNT - 1; i++) {
bytes32[] memory key = new bytes32[](1);
key[0] = bytes32(i);
world.setRecord(namespace, sourceFile, key, abi.encodePacked(value));
}

// !gasreport Setting the last of 100 keys
world.setRecord(namespace, sourceFile, lastKey, abi.encodePacked(value));

// !gasreport Get list of 100 keys with a given value
bytes32[][] memory keyTuples = getKeysInTable(world, sourceTableId);

// Assert that the list is correct
assertEq(keyTuples.length, AMOUNT);
}

function testGetKeysWithValueMany1000() public {
_installKeysInTableModule();

uint256 AMOUNT = 1000;
uint256 value = 1;

bytes32[] memory lastKey = new bytes32[](1);
lastKey[0] = bytes32(uint256(AMOUNT - 1));

for (uint256 i; i < AMOUNT - 1; i++) {
bytes32[] memory key = new bytes32[](1);
key[0] = bytes32(i);
world.setRecord(namespace, sourceFile, key, abi.encodePacked(value));
}

// !gasreport Setting the last of 1000 keys
world.setRecord(namespace, sourceFile, lastKey, abi.encodePacked(value));

// !gasreport Get list of 1000 keys with a given value
bytes32[][] memory keyTuples = getKeysInTable(world, sourceTableId);

// Assert that the list is correct
assertEq(keyTuples.length, AMOUNT);
}
}
75 changes: 75 additions & 0 deletions packages/world/test/KeysWithValueModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,79 @@ contract KeysWithValueModuleTest is Test {
assertEq(keysWithValue[0], key1);
assertEq(keysWithValue[1], key2);
}

function testGetKeysWithValueMany10() public {
_installKeysWithValueModule();

uint256 amount = 10;
uint256 value = 1;

bytes32[] memory lastKey = new bytes32[](1);
lastKey[0] = bytes32(uint256(amount - 1));

for (uint256 i; i < amount - 1; i++) {
bytes32[] memory key = new bytes32[](1);
key[0] = bytes32(i);
world.setRecord(namespace, sourceName, key, abi.encodePacked(value));
}

// !gasreport Setting the last of 10 keys
world.setRecord(namespace, sourceName, lastKey, abi.encodePacked(value));

// !gasreport Get list of 10 keys with a given value
yonadaa marked this conversation as resolved.
Show resolved Hide resolved
bytes32[] memory keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value));

// Assert that the list is correct
assertEq(keysWithValue.length, amount);
}

function testGetKeysWithValueMany100() public {
_installKeysWithValueModule();

uint256 amount = 100;
uint256 value = 1;

bytes32[] memory lastKey = new bytes32[](1);
lastKey[0] = bytes32(uint256(amount - 1));

for (uint256 i; i < amount - 1; i++) {
bytes32[] memory key = new bytes32[](1);
key[0] = bytes32(i);
world.setRecord(namespace, sourceName, key, abi.encodePacked(value));
}

// !gasreport Setting the last of 100 keys
world.setRecord(namespace, sourceName, lastKey, abi.encodePacked(value));

// !gasreport Get list of 100 keys with a given value
bytes32[] memory keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value));

// Assert that the list is correct
assertEq(keysWithValue.length, amount);
}

function testGetKeysWithValueMany1000() public {
_installKeysWithValueModule();

uint256 amount = 1000;
uint256 value = 1;

bytes32[] memory lastKey = new bytes32[](1);
lastKey[0] = bytes32(uint256(amount - 1));

for (uint256 i; i < amount - 1; i++) {
bytes32[] memory key = new bytes32[](1);
key[0] = bytes32(i);
world.setRecord(namespace, sourceName, key, abi.encodePacked(value));
}

// !gasreport Setting the last of 1000 keys
world.setRecord(namespace, sourceName, lastKey, abi.encodePacked(value));

// !gasreport Get list of 1000 keys with a given value
bytes32[] memory keysWithValue = getKeysWithValue(world, sourceTableId, abi.encode(value));

// Assert that the list is correct
assertEq(keysWithValue.length, amount);
}
}