mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Cache enum.values() in ChartCalculations & TradeStatistics3
Cache enum arrays 'TickUnit.values()' & 'PaymentMethodWrapper.values()' as the JVM makes defensive copies of them every time they are returned, and they are both being used in tight loops. In particular, profiling suggests this will make 'TradeStatistics3.isValid' about twice as fast.
This commit is contained in:
parent
835593f2c9
commit
914d75682c
@ -200,7 +200,9 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
|
||||
TIKKIE,
|
||||
TRANSFERWISE_USD,
|
||||
ACH_TRANSFER,
|
||||
DOMESTIC_WIRE_TRANSFER
|
||||
DOMESTIC_WIRE_TRANSFER;
|
||||
|
||||
private static final PaymentMethodMapper[] values = values(); // cache for perf gain
|
||||
}
|
||||
|
||||
@Getter
|
||||
@ -413,7 +415,7 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
|
||||
return paymentMethod;
|
||||
}
|
||||
try {
|
||||
return PaymentMethodMapper.values()[Integer.parseInt(paymentMethod)].name();
|
||||
return PaymentMethodMapper.values[Integer.parseInt(paymentMethod)].name();
|
||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
||||
return paymentMethod;
|
||||
}
|
||||
|
@ -73,20 +73,21 @@ public class ChartCalculations {
|
||||
dateMapsPerTickUnit.put(tick, new HashMap<>());
|
||||
}
|
||||
|
||||
TradesChartsViewModel.TickUnit[] tickUnits = TradesChartsViewModel.TickUnit.values();
|
||||
tradeStatisticsSet.stream()
|
||||
.filter(e -> e.getCurrency().equals("USD"))
|
||||
.forEach(tradeStatistics -> {
|
||||
for (TradesChartsViewModel.TickUnit tick : TradesChartsViewModel.TickUnit.values()) {
|
||||
long time = roundToTick(tradeStatistics.getLocalDateTime(), tick).getTime();
|
||||
Map<Long, List<TradeStatistics3>> map = dateMapsPerTickUnit.get(tick);
|
||||
for (TradesChartsViewModel.TickUnit tickUnit : tickUnits) {
|
||||
long time = roundToTick(tradeStatistics.getLocalDateTime(), tickUnit).getTime();
|
||||
Map<Long, List<TradeStatistics3>> map = dateMapsPerTickUnit.get(tickUnit);
|
||||
map.computeIfAbsent(time, t -> new ArrayList<>()).add(tradeStatistics);
|
||||
}
|
||||
});
|
||||
|
||||
dateMapsPerTickUnit.forEach((tick, map) -> {
|
||||
dateMapsPerTickUnit.forEach((tickUnit, map) -> {
|
||||
HashMap<Long, Long> priceMap = new HashMap<>();
|
||||
map.forEach((date, tradeStatisticsList) -> priceMap.put(date, getAveragePrice(tradeStatisticsList)));
|
||||
usdAveragePriceMapsPerTickUnit.put(tick, priceMap);
|
||||
usdAveragePriceMapsPerTickUnit.put(tickUnit, priceMap);
|
||||
});
|
||||
return usdAveragePriceMapsPerTickUnit;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user