From 90d0d79cfc8e035ad17a2e18917f68d5a0d88f01 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Tue, 5 Mar 2024 11:19:50 +0000 Subject: [PATCH] feat(gas-report): run gas report with --isolate (#2331) --- .changeset/smart-actors-refuse.md | 5 ++ packages/gas-report/README.md | 2 +- packages/gas-report/ts/index.ts | 2 +- packages/store/gas-report.json | 22 +++---- packages/world-modules/gas-report.json | 82 +++++++++++++------------- packages/world/gas-report.json | 48 +++++++-------- 6 files changed, 83 insertions(+), 78 deletions(-) create mode 100644 .changeset/smart-actors-refuse.md diff --git a/.changeset/smart-actors-refuse.md b/.changeset/smart-actors-refuse.md new file mode 100644 index 0000000000..2a8a688d3e --- /dev/null +++ b/.changeset/smart-actors-refuse.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/gas-report": minor +--- + +Now uses `--isolate` flag in `forge test` for more accurate gas measurement. diff --git a/packages/gas-report/README.md b/packages/gas-report/README.md index 782f3b3a11..f6adb34a47 100644 --- a/packages/gas-report/README.md +++ b/packages/gas-report/README.md @@ -26,7 +26,7 @@ pnpm gas-report --save gas-report.json Or, if you have your own test command, you can pipe the output to `gas-report --stdin`: ```console -GAS_REPORTER_ENABLED=true forge test -vvv | pnpm gas-report --stdin +GAS_REPORTER_ENABLED=true forge test -vvv --isolate | pnpm gas-report --stdin ``` Run `pnpm gas-report --help` for more details. diff --git a/packages/gas-report/ts/index.ts b/packages/gas-report/ts/index.ts index 322d71bd09..cb058492f2 100644 --- a/packages/gas-report/ts/index.ts +++ b/packages/gas-report/ts/index.ts @@ -114,7 +114,7 @@ async function runGasReport(options: Options): Promise { console.log("Done reading stdin"); } else { // Run the default test command to capture the logs - const child = execa("forge", ["test", "-vvv"], { + const child = execa("forge", ["test", "-vvv", "--isolate"], { stdio: ["inherit", "pipe", "inherit"], env: { GAS_REPORTER_ENABLED: "true" }, }); diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 343c6287a0..875198ffec 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -147,13 +147,13 @@ "file": "test/Gas.t.sol", "test": "testCompareAbiEncodeVsCustom", "name": "pass abi encoded bytes to external contract", - "gasUsed": 6549 + "gasUsed": 29493 }, { "file": "test/Gas.t.sol", "test": "testCompareAbiEncodeVsCustom", "name": "pass custom encoded bytes to external contract", - "gasUsed": 1426 + "gasUsed": 23310 }, { "file": "test/Gas.t.sol", @@ -675,7 +675,7 @@ "file": "test/StoreCoreGas.t.sol", "test": "testDeleteDataOffchainTable", "name": "StoreCore: delete record in offchain table", - "gasUsed": 4277 + "gasUsed": 28225 }, { "file": "test/StoreCoreGas.t.sol", @@ -711,19 +711,19 @@ "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "set record on table with subscriber", - "gasUsed": 70986 + "gasUsed": 98286 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "set static field on table with subscriber", - "gasUsed": 19248 + "gasUsed": 52904 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooks", "name": "delete record on table with subscriber", - "gasUsed": 17197 + "gasUsed": 47489 }, { "file": "test/StoreCoreGas.t.sol", @@ -735,19 +735,19 @@ "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "set (dynamic) record on table with subscriber", - "gasUsed": 164119 + "gasUsed": 191643 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "set (dynamic) field on table with subscriber", - "gasUsed": 24430 + "gasUsed": 60374 }, { "file": "test/StoreCoreGas.t.sol", "test": "testHooksDynamicData", "name": "delete (dynamic) record on table with subscriber", - "gasUsed": 18862 + "gasUsed": 49266 }, { "file": "test/StoreCoreGas.t.sol", @@ -903,7 +903,7 @@ "file": "test/StoreCoreGas.t.sol", "test": "testSetDataOffchainTable", "name": "StoreCore: set record in offchain table", - "gasUsed": 7681 + "gasUsed": 32517 }, { "file": "test/StoreCoreGas.t.sol", @@ -921,7 +921,7 @@ "file": "test/StoreHook.t.sol", "test": "testCallHook", "name": "call an enabled hook", - "gasUsed": 15032 + "gasUsed": 37660 }, { "file": "test/StoreHook.t.sol", diff --git a/packages/world-modules/gas-report.json b/packages/world-modules/gas-report.json index f30428b4ca..5c555d87b2 100644 --- a/packages/world-modules/gas-report.json +++ b/packages/world-modules/gas-report.json @@ -3,139 +3,139 @@ "file": "test/ERC20.t.sol", "test": "testApprove", "name": "approve", - "gasUsed": 111908 + "gasUsed": 133324 }, { "file": "test/ERC20.t.sol", "test": "testBurn", "name": "burn", - "gasUsed": 72580 + "gasUsed": 141096 }, { "file": "test/ERC20.t.sol", "test": "testMint", "name": "mint", - "gasUsed": 158419 + "gasUsed": 179835 }, { "file": "test/ERC20.t.sol", "test": "testTransfer", "name": "transfer", - "gasUsed": 90086 + "gasUsed": 145002 }, { "file": "test/ERC20.t.sol", "test": "testTransferFrom", "name": "transferFrom", - "gasUsed": 126121 + "gasUsed": 183189 }, { "file": "test/ERC721.t.sol", "test": "testApproveAllGas", "name": "setApprovalForAll", - "gasUsed": 111531 + "gasUsed": 132887 }, { "file": "test/ERC721.t.sol", "test": "testApproveGas", "name": "approve", - "gasUsed": 85330 + "gasUsed": 136246 }, { "file": "test/ERC721.t.sol", "test": "testBurnGas", "name": "burn", - "gasUsed": 97480 + "gasUsed": 156244 }, { "file": "test/ERC721.t.sol", "test": "testMintGas", "name": "mint", - "gasUsed": 165728 + "gasUsed": 187144 }, { "file": "test/ERC721.t.sol", "test": "testSafeMintToEOAGas", "name": "safeMint", - "gasUsed": 165999 + "gasUsed": 189855 }, { "file": "test/ERC721.t.sol", "test": "testSafeTransferFromToEOAGas", "name": "safeTransferFrom", - "gasUsed": 139054 + "gasUsed": 201362 }, { "file": "test/ERC721.t.sol", "test": "testTransferFromGas", "name": "transferFrom", - "gasUsed": 132422 + "gasUsed": 190290 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallComposite", "name": "install keys in table module", - "gasUsed": 1414379 + "gasUsed": 1456815 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallGas", "name": "install keys in table module", - "gasUsed": 1414379 + "gasUsed": 1456815 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallGas", "name": "set a record on a table with keysInTableModule installed", - "gasUsed": 155023 + "gasUsed": 194431 }, { "file": "test/KeysInTableModule.t.sol", "test": "testInstallSingleton", "name": "install keys in table module", - "gasUsed": 1414379 + "gasUsed": 1456815 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "install keys in table module", - "gasUsed": 1414379 + "gasUsed": 1456815 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "change a composite record on a table with keysInTableModule installed", - "gasUsed": 21240 + "gasUsed": 63600 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookCompositeGas", "name": "delete a composite record on a table with keysInTableModule installed", - "gasUsed": 147495 + "gasUsed": 226515 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "install keys in table module", - "gasUsed": 1414379 + "gasUsed": 1456815 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "change a record on a table with keysInTableModule installed", - "gasUsed": 19963 + "gasUsed": 62271 }, { "file": "test/KeysInTableModule.t.sol", "test": "testSetAndDeleteRecordHookGas", "name": "delete a record on a table with keysInTableModule installed", - "gasUsed": 79576 + "gasUsed": 144756 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testGetKeysWithValueGas", "name": "install keys with value module", - "gasUsed": 673326 + "gasUsed": 715762 }, { "file": "test/KeysWithValueModule.t.sol", @@ -153,49 +153,49 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testInstall", "name": "install keys with value module", - "gasUsed": 673326 + "gasUsed": 715762 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testInstall", "name": "set a record on a table with KeysWithValueModule installed", - "gasUsed": 132846 + "gasUsed": 168254 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "install keys with value module", - "gasUsed": 673326 + "gasUsed": 715762 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "change a record on a table with KeysWithValueModule installed", - "gasUsed": 101800 + "gasUsed": 159608 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "delete a record on a table with KeysWithValueModule installed", - "gasUsed": 34255 + "gasUsed": 78835 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "install keys with value module", - "gasUsed": 673326 + "gasUsed": 715762 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "set a field on a table with KeysWithValueModule installed", - "gasUsed": 144056 + "gasUsed": 179348 }, { "file": "test/KeysWithValueModule.t.sol", "test": "testSetField", "name": "change a field on a table with KeysWithValueModule installed", - "gasUsed": 108743 + "gasUsed": 158835 }, { "file": "test/query.t.sol", @@ -267,60 +267,60 @@ "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromCallboundDelegation", "name": "register a callbound delegation", - "gasUsed": 116008 + "gasUsed": 139044 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromCallboundDelegation", "name": "call a system via a callbound delegation", - "gasUsed": 34757 + "gasUsed": 67297 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromSystemDelegation", "name": "register a systembound delegation", - "gasUsed": 113562 + "gasUsed": 136166 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromSystemDelegation", "name": "call a system via a systembound delegation", - "gasUsed": 32321 + "gasUsed": 69661 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromTimeboundDelegation", "name": "register a timebound delegation", - "gasUsed": 110497 + "gasUsed": 132709 }, { "file": "test/StandardDelegationsModule.t.sol", "test": "testCallFromTimeboundDelegation", "name": "call a system via a timebound delegation", - "gasUsed": 25687 + "gasUsed": 58227 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstall", "name": "install unique entity module", - "gasUsed": 688807 + "gasUsed": 710507 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstall", "name": "get a unique entity nonce (non-root module)", - "gasUsed": 49452 + "gasUsed": 77840 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstallRoot", "name": "installRoot unique entity module", - "gasUsed": 659276 + "gasUsed": 680976 }, { "file": "test/UniqueEntityModule.t.sol", "test": "testInstallRoot", "name": "get a unique entity nonce (root module)", - "gasUsed": 49455 + "gasUsed": 77843 } ] diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index 6b913e22c6..1eb0de70d3 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -45,145 +45,145 @@ "file": "test/BatchCall.t.sol", "test": "testBatchCallFromReturnData", "name": "call systems with batchCallFrom", - "gasUsed": 50689 + "gasUsed": 80765 }, { "file": "test/BatchCall.t.sol", "test": "testBatchCallReturnData", "name": "call systems with batchCall", - "gasUsed": 49764 + "gasUsed": 77560 }, { "file": "test/Factories.t.sol", "test": "testCreate2Factory", "name": "deploy contract via Create2", - "gasUsed": 4615190 + "gasUsed": 4965450 }, { "file": "test/Factories.t.sol", "test": "testWorldFactoryGas", "name": "deploy world via WorldFactory", - "gasUsed": 12643627 + "gasUsed": 12657699 }, { "file": "test/World.t.sol", "test": "testCall", "name": "call a system via the World", - "gasUsed": 11681 + "gasUsed": 40081 }, { "file": "test/World.t.sol", "test": "testCallFromNamespaceDelegation", "name": "call a system via a namespace fallback delegation", - "gasUsed": 24776 + "gasUsed": 59816 }, { "file": "test/World.t.sol", "test": "testCallFromUnlimitedDelegation", "name": "register an unlimited delegation", - "gasUsed": 46495 + "gasUsed": 74727 }, { "file": "test/World.t.sol", "test": "testCallFromUnlimitedDelegation", "name": "call a system via an unlimited delegation", - "gasUsed": 12123 + "gasUsed": 40663 }, { "file": "test/World.t.sol", "test": "testDeleteRecord", "name": "Delete record", - "gasUsed": 8958 + "gasUsed": 36718 }, { "file": "test/World.t.sol", "test": "testPushToDynamicField", "name": "Push data to the table", - "gasUsed": 85647 + "gasUsed": 110775 }, { "file": "test/World.t.sol", "test": "testRegisterFunctionSelector", "name": "Register a function selector", - "gasUsed": 79089 + "gasUsed": 111621 }, { "file": "test/World.t.sol", "test": "testRegisterNamespace", "name": "Register a new namespace", - "gasUsed": 122690 + "gasUsed": 144062 }, { "file": "test/World.t.sol", "test": "testRegisterRootFunctionSelector", "name": "Register a root function selector", - "gasUsed": 78683 + "gasUsed": 107427 }, { "file": "test/World.t.sol", "test": "testRegisterSystem", "name": "register a system", - "gasUsed": 161017 + "gasUsed": 185337 }, { "file": "test/World.t.sol", "test": "testRegisterTable", "name": "Register a new table in the namespace", - "gasUsed": 532676 + "gasUsed": 569676 }, { "file": "test/World.t.sol", "test": "testRenounceNamespace", "name": "Renounce namespace ownership", - "gasUsed": 34830 + "gasUsed": 62190 }, { "file": "test/World.t.sol", "test": "testSetField", "name": "Write data to a table field", - "gasUsed": 36436 + "gasUsed": 60884 }, { "file": "test/World.t.sol", "test": "testSetRecord", "name": "Write data to the table", - "gasUsed": 38167 + "gasUsed": 64743 }, { "file": "test/World.t.sol", "test": "testUnregisterNamespaceDelegation", "name": "unregister a namespace delegation", - "gasUsed": 26404 + "gasUsed": 60328 }, { "file": "test/World.t.sol", "test": "testUnregisterUnlimitedDelegation", "name": "unregister an unlimited delegation", - "gasUsed": 24722 + "gasUsed": 54526 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testPopFromDynamicField", "name": "pop 1 address (cold)", - "gasUsed": 25434 + "gasUsed": 51686 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testPopFromDynamicField", "name": "pop 1 address (warm)", - "gasUsed": 12580 + "gasUsed": 45632 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testSpliceDynamicData", "name": "update in field 1 item (cold)", - "gasUsed": 25794 + "gasUsed": 52822 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testSpliceDynamicData", "name": "update in field 1 item (warm)", - "gasUsed": 12995 + "gasUsed": 44023 }, { "file": "test/WorldResourceId.t.sol",