Skip to content

[BUG] - Eq instance for txid allocates memory #2003

Description

@karknu

Internal

Summary
Profiling with cardano-ignite highlighted a performance problem tied to the Eq/Ord instance for txid.

This is the code that is causing performance problems:

oneEraGenTxIdRawHash :: CanHardFork xs => OneEraGenTxId xs -> ShortByteString
oneEraGenTxIdRawHash =
  hcollapse
    . hcmap proxySingle (K . toRawTxIdHash . unwrapGenTxId)
    . getOneEraGenTxId

Every node is expected to talk to 10s or 100s of down stream peers. All of them will present the node with mostly the same txs. To keep track of that and to acknowledge TXs already in our mempool the network layer maintains structures keyed on txid. This turns into a lot of extra allocations even today, and with Leios it will get a lot worse.

A work-around like this in ouroboros-network-api removed the issue, but it would be better if it is fixed in consensus.

-- | Raw byte representation of a transaction identifier.
newtype RawTxId = RawTxId ShortByteString
  deriving newtype (Eq, Ord, Show, NFData, NoThunks)

-- | Abstract over transaction identifiers,
--
-- Laws:
--
-- * If @getRawTxId x == getRawTxId y@ then @x == y@
--   (the raw bytes must uniquely identify the transaction)
class HasRawTxId txid where
  getRawTxId :: txid -> RawTxId 

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
🏗 In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions