Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up loading and scrolling of trade history #6552

Conversation

stejbac
Copy link
Contributor

@stejbac stejbac commented Feb 2, 2023

This PR fixes a quadratic time bug while filtering the list of BSQ swap trades for their tx confirmation status, as needed by ClosedTradesView. It also fixes a (sort-of) cubic time bug caused by the repeated invocation of ClosedTradableManager.getNumPastTrades (once for each list item). It does this by caching the peer node address counts over all the closed trades & confirmed BSQ swaps, as well as caching a mapping of txIds to txs in WalletService to avoid repeated copying and scanning of the wallet tx list while checking for confirmation status by txId.

These issues were making the closed trades view load extremely slow on my Bisq instance (taking more than 20s), which has around 1300 past trades, a bit under half of which are BSQ swaps. It was also making scrolling and paging almost unusable. The following is a screenshot of the hotspots from JProfiler, prior to the changes:
Screenshot from 2023-02-02 10-53-51

Reduce a bottleneck in the closed-trades-view load & table scrolling,
caused by a call to 'ClosedTradesManager.getNumPastTrades' for each
list item displayed. This repeatedly scans the entire collection of
closed trades and BSQ swap trades, in order to count all those which
share a given peer node address. (Scanning the BSQ swap trades is
particularly slow due to their filtering by tx confirmation status.)

To this end, cache the counts of trades by peer node address with a
nullable Multiset field in ClosedTradesManager & BsqSwapTradeManager,
so that the trades are scanned at most once when the view loads. Add
listeners to clear the respective cache when the trade list changes or
the BSQ wallet txs change.
The return value is a (cached) SetMultimap, not a multiset.
Add a third cache to WalletService, cleared upon wallet change events,
which maps txIds to txs. This allows the speedup of repeated calls to
'WalletService.getConfidenceForTxId', by avoiding the need to copy and
scan the entire set of wallet txs to find the one with matching id,
for each method invocation.

This is mainly to provide a further speedup to the closed-trades-view
load, by making it much faster to filter the list of BSQ swap trades by
tx confirmation status in 'ClosedTradesDataModel.applyList' and
'ClosedTradesManager.getNumPastTrades'.
@alejandrogarcia83 alejandrogarcia83 added this to the v1.9.10 milestone Feb 3, 2023
@alejandrogarcia83
Copy link
Contributor

alejandrogarcia83 commented Feb 3, 2023

Hey @stejbac ,
thank you for the awesome contributions!! Caching will definitely improve the performance and many computations were redundant.

Copy link
Contributor

@alejandrogarcia83 alejandrogarcia83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK

@alejandrogarcia83 alejandrogarcia83 merged commit 2239924 into bisq-network:master Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants