From 004629fd8b40ce895381ace412c5fbcae6878294 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Tue, 25 Jun 2024 23:45:14 +0200 Subject: [PATCH] Small cleanups * remove unnecessary / expensive error checking * avoid some trivial memory allocs * work around table move bug --- nimbus/db/aristo/aristo_delta.nim | 2 +- nimbus/db/aristo/aristo_desc/desc_error.nim | 1 - nimbus/db/aristo/aristo_hashify.nim | 9 +++++---- nimbus/db/aristo/aristo_utils.nim | 11 ++--------- nimbus/db/ledger/accounts_ledger.nim | 4 +++- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/nimbus/db/aristo/aristo_delta.nim b/nimbus/db/aristo/aristo_delta.nim index 6c0ded6b7..0ae96f4ee 100644 --- a/nimbus/db/aristo/aristo_delta.nim +++ b/nimbus/db/aristo/aristo_delta.nim @@ -13,7 +13,7 @@ ## import - std/[sequtils, tables], + std/tables, eth/common, results, ./aristo_desc, diff --git a/nimbus/db/aristo/aristo_desc/desc_error.nim b/nimbus/db/aristo/aristo_desc/desc_error.nim index 6bd29727a..6a1c4d7ad 100644 --- a/nimbus/db/aristo/aristo_desc/desc_error.nim +++ b/nimbus/db/aristo/aristo_desc/desc_error.nim @@ -303,7 +303,6 @@ type UtilsAccVtxUnsupported UtilsAccWrongStorageRoot UtilsPayloadTypeUnsupported - UtilsStoRootInaccessible UtilsStoRootMissing # End diff --git a/nimbus/db/aristo/aristo_hashify.nim b/nimbus/db/aristo/aristo_hashify.nim index 47fd68eed..c138d87a3 100644 --- a/nimbus/db/aristo/aristo_hashify.nim +++ b/nimbus/db/aristo/aristo_hashify.nim @@ -65,7 +65,7 @@ func getOrVoid(tab: Table[VertexID,VertexID]; vid: VertexID): VertexID = func hasValue( wffTable: Table[VertexID,VertexID]; vid: VertexID; - wff: WidthFirstForest; + wff: var WidthFirstForest; ): bool = ## Helper for efficient `value` access: ## :: @@ -75,9 +75,10 @@ func hasValue( ## :: ## vid in wffTable.values.toSeq ## - for w in wff.rev.getOrVoid vid: - if w in wffTable: - return true + wff.rev.withValue(vid, v): + for w in v[]: + if w in wffTable: + return true proc pedigree( diff --git a/nimbus/db/aristo/aristo_utils.nim b/nimbus/db/aristo/aristo_utils.nim index db1838dbd..a8292f953 100644 --- a/nimbus/db/aristo/aristo_utils.nim +++ b/nimbus/db/aristo/aristo_utils.nim @@ -184,7 +184,7 @@ proc retrieveStoAccHike*( ## vertex and the vertex ID. ## # Expand vertex path to account leaf - let hike = accPath.to(NibblesBuf).hikeUp(VertexID(1), db).valueOr: + var hike = accPath.to(NibblesBuf).hikeUp(VertexID(1), db).valueOr: return err(UtilsAccInaccessible) # Extract the account payload fro the leaf @@ -192,15 +192,8 @@ proc retrieveStoAccHike*( if wp.vtx.vType != Leaf: return err(UtilsAccPathWithoutLeaf) assert wp.vtx.lData.pType == AccountData # debugging only - let acc = wp.vtx.lData.account - # Check whether storage ID exists, at all - if acc.storageID.isValid: - # Verify that the storage root `acc.storageID` exists on the databse - discard db.getVtxRc(acc.storageID).valueOr: - return err(UtilsStoRootInaccessible) - - ok(hike) + ok(move(hike)) proc updateAccountForHasher*( db: AristoDbRef; # Database diff --git a/nimbus/db/ledger/accounts_ledger.nim b/nimbus/db/ledger/accounts_ledger.nim index d65cab878..076fc6a6d 100644 --- a/nimbus/db/ledger/accounts_ledger.nim +++ b/nimbus/db/ledger/accounts_ledger.nim @@ -695,7 +695,9 @@ proc persist*(ac: AccountsLedgerRef, if clearCache: # This overwrites the cache from the previous persist, providing a crude LRU # scheme with little overhead - ac.cache = move(ac.savePoint.cache) + # TODO https://github.com/nim-lang/Nim/issues/23759 + swap(ac.cache, ac.savePoint.cache) + ac.savePoint.cache.reset() ac.savePoint.selfDestruct.clear()