mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Speed up burn target calculations in burning man view
Optimise 'BurningManPresentationService.getCandidateBurnTarget' to avoid the repeated computation of the total accumulated decayed burned amount for every listed burning man. To this end, cache the total in a nullable Long field, along with the method 'getAccumulatedDecayedBurnedAmount()' to lazily initialise it. (This eliminates a minor hotspot in the burning man view revealed by JProfiler.)
This commit is contained in:
parent
9ce9ffc694
commit
e287177e49
@ -90,6 +90,7 @@ public class BurningManPresentationService implements DaoStateListener {
|
|||||||
private int currentChainHeight;
|
private int currentChainHeight;
|
||||||
private Optional<Long> burnTarget = Optional.empty();
|
private Optional<Long> burnTarget = Optional.empty();
|
||||||
private final Map<String, BurningManCandidate> burningManCandidatesByName = new HashMap<>();
|
private final Map<String, BurningManCandidate> burningManCandidatesByName = new HashMap<>();
|
||||||
|
private Long accumulatedDecayedBurnedAmount;
|
||||||
private final Set<ReimbursementModel> reimbursements = new HashSet<>();
|
private final Set<ReimbursementModel> reimbursements = new HashSet<>();
|
||||||
private Optional<Long> averageDistributionPerCycle = Optional.empty();
|
private Optional<Long> averageDistributionPerCycle = Optional.empty();
|
||||||
private Set<String> myCompensationRequestNames = null;
|
private Set<String> myCompensationRequestNames = null;
|
||||||
@ -132,6 +133,7 @@ public class BurningManPresentationService implements DaoStateListener {
|
|||||||
burningManCandidatesByName.clear();
|
burningManCandidatesByName.clear();
|
||||||
reimbursements.clear();
|
reimbursements.clear();
|
||||||
burnTarget = Optional.empty();
|
burnTarget = Optional.empty();
|
||||||
|
accumulatedDecayedBurnedAmount = null;
|
||||||
myCompensationRequestNames = null;
|
myCompensationRequestNames = null;
|
||||||
averageDistributionPerCycle = Optional.empty();
|
averageDistributionPerCycle = Optional.empty();
|
||||||
legacyBurningManDPT = Optional.empty();
|
legacyBurningManDPT = Optional.empty();
|
||||||
@ -188,8 +190,7 @@ public class BurningManPresentationService implements DaoStateListener {
|
|||||||
long lowerBaseTarget = Math.round(burnTarget * maxCompensationShare);
|
long lowerBaseTarget = Math.round(burnTarget * maxCompensationShare);
|
||||||
double maxBoostedCompensationShare = burningManCandidate.getMaxBoostedCompensationShare();
|
double maxBoostedCompensationShare = burningManCandidate.getMaxBoostedCompensationShare();
|
||||||
long upperBaseTarget = Math.round(boostedBurnTarget * maxBoostedCompensationShare);
|
long upperBaseTarget = Math.round(boostedBurnTarget * maxBoostedCompensationShare);
|
||||||
Collection<BurningManCandidate> burningManCandidates = getBurningManCandidatesByName().values();
|
long totalBurnedAmount = getAccumulatedDecayedBurnedAmount();
|
||||||
long totalBurnedAmount = burnTargetService.getAccumulatedDecayedBurnedAmount(burningManCandidates, currentChainHeight);
|
|
||||||
|
|
||||||
if (totalBurnedAmount == 0) {
|
if (totalBurnedAmount == 0) {
|
||||||
// The first BM would reach their max burn share by 5.46 BSQ already. But we suggest the lowerBaseTarget
|
// The first BM would reach their max burn share by 5.46 BSQ already. But we suggest the lowerBaseTarget
|
||||||
@ -344,7 +345,6 @@ public class BurningManPresentationService implements DaoStateListener {
|
|||||||
receiverAddressesByBurningManName.get(name).addAll(burningManCandidate.getAllAddresses());
|
receiverAddressesByBurningManName.get(name).addAll(burningManCandidate.getAllAddresses());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
receiverAddressesByBurningManName
|
receiverAddressesByBurningManName
|
||||||
.forEach((name, addresses) -> addresses
|
.forEach((name, addresses) -> addresses
|
||||||
@ -371,4 +371,12 @@ public class BurningManPresentationService implements DaoStateListener {
|
|||||||
proofOfBurnOpReturnTxOutputByHash.putAll(burningManService.getProofOfBurnOpReturnTxOutputByHash(currentChainHeight));
|
proofOfBurnOpReturnTxOutputByHash.putAll(burningManService.getProofOfBurnOpReturnTxOutputByHash(currentChainHeight));
|
||||||
return proofOfBurnOpReturnTxOutputByHash;
|
return proofOfBurnOpReturnTxOutputByHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long getAccumulatedDecayedBurnedAmount() {
|
||||||
|
if (accumulatedDecayedBurnedAmount == null) {
|
||||||
|
Collection<BurningManCandidate> burningManCandidates = getBurningManCandidatesByName().values();
|
||||||
|
accumulatedDecayedBurnedAmount = burnTargetService.getAccumulatedDecayedBurnedAmount(burningManCandidates, currentChainHeight);
|
||||||
|
}
|
||||||
|
return accumulatedDecayedBurnedAmount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user