Skip to content

Commit

Permalink
gas: optimize storage warmup function
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrai committed Dec 8, 2023
1 parent 9f8fd23 commit 6196690
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
25 changes: 13 additions & 12 deletions packages/nouns-contracts/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
NounsAuctionHouseV2WarmedUp_GasSnapshot:test_createOneBid() (gas: 34963)
NounsAuctionHouseV2WarmedUp_GasSnapshot:test_createTwoBids() (gas: 93423)
NounsAuctionHouseV2WarmedUp_GasSnapshot:test_settleCurrentAndCreateNewAuction() (gas: 232686)
NounsAuctionHouseV2_GasSnapshot:test_createOneBid() (gas: 34963)
NounsAuctionHouseV2_GasSnapshot:test_createTwoBids() (gas: 93423)
NounsAuctionHouseV2_GasSnapshot:test_settleCurrentAndCreateNewAuction() (gas: 249786)
NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_getPrices_90() (gas: 310063)
NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_getPrices_range_90() (gas: 300578)
NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_getSettlements_90() (gas: 385762)
NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_getSettlements_range_90() (gas: 378168)
NounsAuctionHouseV2WarmedUp_GasSnapshot:test_createOneBid() (gas: 34941)
NounsAuctionHouseV2WarmedUp_GasSnapshot:test_createTwoBids() (gas: 93380)
NounsAuctionHouseV2WarmedUp_GasSnapshot:test_settleCurrentAndCreateNewAuction() (gas: 232656)
NounsAuctionHouseV2_GasSnapshot:test_createOneBid() (gas: 34941)
NounsAuctionHouseV2_GasSnapshot:test_createTwoBids() (gas: 93380)
NounsAuctionHouseV2_GasSnapshot:test_settleCurrentAndCreateNewAuction() (gas: 249756)
NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_getPrices_90() (gas: 309530)
NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_getPrices_range_90() (gas: 299984)
NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_getSettlements_90() (gas: 385118)
NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_getSettlements_range_90() (gas: 377552)
NounsAuctionHouseV2_HistoricPrices_GasSnapshot:test_warmUp() (gas: 18716918)
NounsAuctionHouse_GasSnapshot:test_createOneBid() (gas: 81474)
NounsAuctionHouse_GasSnapshot:test_createTwoBids() (gas: 142736)
NounsAuctionHouse_GasSnapshot:test_settleCurrentAndCreateNewAuction() (gas: 243008)
NounsDAOLogic_GasSnapshot_V2_propose:test_propose_longDescription() (gas: 528754)
NounsDAOLogic_GasSnapshot_V2_propose:test_propose_shortDescription() (gas: 398387)
NounsDAOLogic_GasSnapshot_V2_propose:test_propose_longDescription() (gas: 528755)
NounsDAOLogic_GasSnapshot_V2_propose:test_propose_shortDescription() (gas: 398388)
NounsDAOLogic_GasSnapshot_V2_vote:test_castVoteWithReason() (gas: 83585)
NounsDAOLogic_GasSnapshot_V2_vote:test_castVote_against() (gas: 82930)
NounsDAOLogic_GasSnapshot_V2_vote:test_castVote_lastMinuteFor() (gas: 83481)
Expand Down
12 changes: 9 additions & 3 deletions packages/nouns-contracts/contracts/NounsAuctionHouseV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,15 @@ contract NounsAuctionHouseV2 is
* @param nounIds The list of Noun IDs whose settlement slot to warm up.
*/
function warmUpSettlementState(uint256[] calldata nounIds) external {
for (uint256 i = 0; i < nounIds.length; ++i) {
if (settlementHistory[nounIds[i]].blockTimestamp == 0) {
settlementHistory[nounIds[i]] = SettlementState({ blockTimestamp: 1, amount: 0, winner: address(0) });
uint256 nounIdCount = nounIds.length;
SettlementState storage settlementState;
for (uint256 i; i < nounIdCount; ) {
settlementState = settlementHistory[nounIds[i]];
if (settlementState.blockTimestamp == 0) {
settlementState.blockTimestamp = 1;
}
unchecked {
++i;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,12 @@ contract NounsAuctionHouseV2_HistoricPrices_GasSnapshot is NounsAuctionHouseBase
uint256[] memory prices = auctionHouseV2.getPrices(1, 100);
assertEq(prices.length, 90);
}

function test_warmUp() public {
uint256[] memory nounIds = new uint256[](1000);
for (uint256 i; i < 1000; ++i) {
nounIds[i] = i;
}
auctionHouseV2.warmUpSettlementState(nounIds);
}
}

0 comments on commit 6196690

Please sign in to comment.