Skip to content

Commit

Permalink
Minor performance improvements in UTxO aggregation
Browse files Browse the repository at this point in the history
This makes a couple of minor improvements in the function
'aggregateUtxoCoinByCredential', as measured by the new benchmark
introduced.

I tried a few variants; see
https://drive.google.com/drive/u/1/folders/1o7r4EF0uM5gfhtf3_GoMSJdoHc_d6Xtc
for the full reports. This version seems to shave maybe 20% off of the
20K UTxO run.

Interestingly, a variant where we try to explicitly deserialise only the
stake ref (using `deserialiseAddrStakeRef`) was _considerably_ slower.
I'm not immediately sure why!
  • Loading branch information
nc6 committed Apr 19, 2021
1 parent 6ef64f7 commit b4d3148
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
Expand Down Expand Up @@ -105,15 +106,17 @@ deriving newtype instance
-- | Sum up all the Coin for each staking Credential
aggregateUtxoCoinByCredential ::
forall era.
(Era era, HasField "address" (Core.TxOut era) (Addr (Crypto era))) =>
( Era era,
HasField "address" (Core.TxOut era) (Addr (Crypto era))
) =>
Map Ptr (Credential 'Staking (Crypto era)) ->
UTxO era ->
Map (Credential 'Staking (Crypto era)) Coin ->
Map (Credential 'Staking (Crypto era)) Coin
aggregateUtxoCoinByCredential ptrs (UTxO u) initial =
Map.foldr accum initial u
Map.foldl' accum initial u
where
accum out ans =
accum !ans out =
case (getField @"address" out, getField @"value" out) of
(Addr _ _ (StakeRefPtr p), c) ->
case Map.lookup p ptrs of
Expand Down

0 comments on commit b4d3148

Please sign in to comment.