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

Optimize trade chart view [6] #5794

Merged
merged 12 commits into from
Nov 9, 2021

Conversation

chimp1984
Copy link
Contributor

@chimp1984 chimp1984 commented Nov 2, 2021

Based on #5790

Starts at ebf5eac

This optimizes performance and memory usage of the Trade Charts view (market).
It uses about 620MB (in JProfiler) when visible and 600 MB when at other view.
Before it was about 680-700 MB and memory did not really go lower when moving away (as we kept the data structures for caching).

It uses CompletableFutures and moved all heavy calculation code to static methods. So at view activation there is nothing heavy left on the UI thread and it can render faster, and as soon the tasks are completed the UI gets updated to render the table and charts.
I think that pattern can be used elsewhere (like BSQ Dashboard which also uses the trade stats and is therefore heavy). But it requires caution to not call JavaFx controls from a non UI thread.

EDIT: Merged and rebased with #5790

@chimp1984 chimp1984 changed the title Optimize trade chart view 6 Optimize trade chart view [6] Nov 2, 2021
@chimp1984 chimp1984 requested a review from sqrrm November 2, 2021 00:25
@chimp1984 chimp1984 force-pushed the optimize-trade-chart-view-6 branch from dd0202d to 4369db3 Compare November 2, 2021 18:19
@ripcurlx ripcurlx added this to the v1.8.0 milestone Nov 4, 2021
@chimp1984 chimp1984 force-pushed the optimize-trade-chart-view-6 branch from 4369db3 to 45a40ab Compare November 4, 2021 12:35
@ripcurlx
Copy link
Contributor

ripcurlx commented Nov 9, 2021

I'm starting to review from 6cc4265 onwards.

ripcurlx
ripcurlx previously approved these changes Nov 9, 2021
Copy link
Contributor

@ripcurlx ripcurlx left a comment

Choose a reason for hiding this comment

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

ACK - Reviewed code and tested it on Mainnet. Will wait for final test and merge after rebase to master.

Make buildUsdPricesPerTickUnit static and pass params
Rename usdPriceMapsPerTickUnit to usdAveragePriceMapsPerTickUnit
Rename local variable map to usdAveragePriceMap

Move method calls syncPriceFeedCurrency() and
setMarketPriceFeedCurrency() before other calls (those will become async later)
use it instead of updateSelectedTradeStatistics
(preparation for follow up commit)
Convenience util for CompletableFuture.allOf method
The creation of TradeStatistics3ListItem is rather fast but the
applying to the list is due sorting pretty slow (300 ms) as
its > 100k items. We do the applying on the callback thread.
Seems JavaFx permits that. So we can keep the UI thread unblocked.

Remove modelReadyListener

Renamed model.selectedTradeStatistics to model.tradeStatisticsByCurrency
in parallel and once both are done we call asyncUpdateChartData (not yet refactored).

Clear all data at deactivate
This cause a bit of costs when we activate again but as we delegate
now all work to threads it should be OK. It decreases the memory usage
if we do not keep those data in the fields. The View classes are cached
in the view loader so all data in fields stays in memory once it was
activated once and not manually cleared in deactivate.

Move getTradeStatisticsForCurrency to ChartCalculations
Rename buildUsdPricesPerTickUnit to getUsdAveragePriceMapsPerTickUnit
Rename selectedTradeStatistics to tradeStatisticsByCurrency
Make itemsPerInterval final
Remove modelReady
Add deactivateCalled flag
…rtCalculations

Make maxTicks static and rename to MAX_TICKS
it to table in UI thread afterwards.

Chain updateSelectedTradeStatistics and updateChartData calls.
@chimp1984
Copy link
Contributor Author

Merged/Rebased with master

ripcurlx
ripcurlx previously approved these changes Nov 9, 2021
Copy link
Contributor

@ripcurlx ripcurlx left a comment

Choose a reason for hiding this comment

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

ACK

Copy link
Contributor

@ripcurlx ripcurlx left a comment

Choose a reason for hiding this comment

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

ACK

@ripcurlx ripcurlx merged commit 07f4074 into bisq-network:master Nov 9, 2021
@chimp1984 chimp1984 deleted the optimize-trade-chart-view-6 branch November 18, 2021 00:54
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