mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +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,
|
TIKKIE,
|
||||||
TRANSFERWISE_USD,
|
TRANSFERWISE_USD,
|
||||||
ACH_TRANSFER,
|
ACH_TRANSFER,
|
||||||
DOMESTIC_WIRE_TRANSFER
|
DOMESTIC_WIRE_TRANSFER;
|
||||||
|
|
||||||
|
private static final PaymentMethodMapper[] values = values(); // cache for perf gain
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -413,7 +415,7 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
|
|||||||
return paymentMethod;
|
return paymentMethod;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return PaymentMethodMapper.values()[Integer.parseInt(paymentMethod)].name();
|
return PaymentMethodMapper.values[Integer.parseInt(paymentMethod)].name();
|
||||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
||||||
return paymentMethod;
|
return paymentMethod;
|
||||||
}
|
}
|
||||||
|
@ -73,20 +73,21 @@ public class ChartCalculations {
|
|||||||
dateMapsPerTickUnit.put(tick, new HashMap<>());
|
dateMapsPerTickUnit.put(tick, new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TradesChartsViewModel.TickUnit[] tickUnits = TradesChartsViewModel.TickUnit.values();
|
||||||
tradeStatisticsSet.stream()
|
tradeStatisticsSet.stream()
|
||||||
.filter(e -> e.getCurrency().equals("USD"))
|
.filter(e -> e.getCurrency().equals("USD"))
|
||||||
.forEach(tradeStatistics -> {
|
.forEach(tradeStatistics -> {
|
||||||
for (TradesChartsViewModel.TickUnit tick : TradesChartsViewModel.TickUnit.values()) {
|
for (TradesChartsViewModel.TickUnit tickUnit : tickUnits) {
|
||||||
long time = roundToTick(tradeStatistics.getLocalDateTime(), tick).getTime();
|
long time = roundToTick(tradeStatistics.getLocalDateTime(), tickUnit).getTime();
|
||||||
Map<Long, List<TradeStatistics3>> map = dateMapsPerTickUnit.get(tick);
|
Map<Long, List<TradeStatistics3>> map = dateMapsPerTickUnit.get(tickUnit);
|
||||||
map.computeIfAbsent(time, t -> new ArrayList<>()).add(tradeStatistics);
|
map.computeIfAbsent(time, t -> new ArrayList<>()).add(tradeStatistics);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dateMapsPerTickUnit.forEach((tick, map) -> {
|
dateMapsPerTickUnit.forEach((tickUnit, map) -> {
|
||||||
HashMap<Long, Long> priceMap = new HashMap<>();
|
HashMap<Long, Long> priceMap = new HashMap<>();
|
||||||
map.forEach((date, tradeStatisticsList) -> priceMap.put(date, getAveragePrice(tradeStatisticsList)));
|
map.forEach((date, tradeStatisticsList) -> priceMap.put(date, getAveragePrice(tradeStatisticsList)));
|
||||||
usdAveragePriceMapsPerTickUnit.put(tick, priceMap);
|
usdAveragePriceMapsPerTickUnit.put(tickUnit, priceMap);
|
||||||
});
|
});
|
||||||
return usdAveragePriceMapsPerTickUnit;
|
return usdAveragePriceMapsPerTickUnit;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user