From 02d163f5dc608fbc7d27c6f53deb2b4e7896cf22 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 15 Dec 2020 00:56:06 -0500 Subject: [PATCH 1/5] Only log in case the operation took longer than 100 ms --- .../bisq/common/persistence/PersistenceManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/bisq/common/persistence/PersistenceManager.java b/common/src/main/java/bisq/common/persistence/PersistenceManager.java index 8300e9c336..27fffacdad 100644 --- a/common/src/main/java/bisq/common/persistence/PersistenceManager.java +++ b/common/src/main/java/bisq/common/persistence/PersistenceManager.java @@ -375,7 +375,10 @@ public class PersistenceManager { // reference to the persistable object. getWriteToDiskExecutor().execute(() -> writeToDisk(serialized, completeHandler)); - log.info("Serializing {} took {} msec", fileName, System.currentTimeMillis() - ts); + long duration = System.currentTimeMillis() - ts; + if (duration > 100) { + log.info("Serializing {} took {} msec", fileName, duration); + } } catch (Throwable e) { log.error("Error in saveToFile toProtoMessage: {}, {}", persistable.getClass().getSimpleName(), fileName); e.printStackTrace(); @@ -437,7 +440,10 @@ public class PersistenceManager { e.printStackTrace(); log.error("Cannot close resources." + e.getMessage()); } - log.info("Writing the serialized {} completed in {} msec", fileName, System.currentTimeMillis() - ts); + long duration = System.currentTimeMillis() - ts; + if (duration > 100) { + log.info("Writing the serialized {} completed in {} msec", fileName, duration); + } persistenceRequested = false; if (completeHandler != null) { UserThread.execute(completeHandler); From 9fc4f61bf6f9975d2fdb293a3da0f3ddf91ecebd Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 15 Dec 2020 00:59:05 -0500 Subject: [PATCH 2/5] Cache currencyCode Extract variable getCurrencyCode get called very often (Comparatos) so we cache result. --- core/src/main/java/bisq/core/offer/Offer.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/Offer.java b/core/src/main/java/bisq/core/offer/Offer.java index bcca0078b4..5c1c4051ef 100644 --- a/core/src/main/java/bisq/core/offer/Offer.java +++ b/core/src/main/java/bisq/core/offer/Offer.java @@ -109,6 +109,10 @@ public class Offer implements NetworkPayload, PersistablePayload { @Setter transient private PriceFeedService priceFeedService; + // Used only as cache + @Nullable + transient private String currencyCode; + /////////////////////////////////////////////////////////////////////////////////////////// // Constructor @@ -346,8 +350,9 @@ public class Offer implements NetworkPayload, PersistablePayload { public Optional getAccountAgeWitnessHashAsHex() { - if (getExtraDataMap() != null && getExtraDataMap().containsKey(OfferPayload.ACCOUNT_AGE_WITNESS_HASH)) - return Optional.of(getExtraDataMap().get(OfferPayload.ACCOUNT_AGE_WITNESS_HASH)); + Map extraDataMap = getExtraDataMap(); + if (extraDataMap != null && extraDataMap.containsKey(OfferPayload.ACCOUNT_AGE_WITNESS_HASH)) + return Optional.of(extraDataMap.get(OfferPayload.ACCOUNT_AGE_WITNESS_HASH)); else return Optional.empty(); } @@ -421,9 +426,14 @@ public class Offer implements NetworkPayload, PersistablePayload { } public String getCurrencyCode() { - return offerPayload.getBaseCurrencyCode().equals("BTC") ? + if (currencyCode != null) { + return currencyCode; + } + + currencyCode = offerPayload.getBaseCurrencyCode().equals("BTC") ? offerPayload.getCounterCurrencyCode() : offerPayload.getBaseCurrencyCode(); + return currencyCode; } public long getProtocolVersion() { From 1ddde42e17cf08d9ef7a8a98612810f7a17a3c44 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 15 Dec 2020 01:02:49 -0500 Subject: [PATCH 3/5] Keep Date as transient field to avoid recreating a Data object at each getDate call. Add JsonExclude to Offer.currencyCode getDate get called very often and we have > 80k objects. --- core/src/main/java/bisq/core/offer/Offer.java | 1 + .../java/bisq/core/trade/statistics/TradeStatistics3.java | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/offer/Offer.java b/core/src/main/java/bisq/core/offer/Offer.java index 5c1c4051ef..963009a0d2 100644 --- a/core/src/main/java/bisq/core/offer/Offer.java +++ b/core/src/main/java/bisq/core/offer/Offer.java @@ -111,6 +111,7 @@ public class Offer implements NetworkPayload, PersistablePayload { // Used only as cache @Nullable + @JsonExclude transient private String currencyCode; diff --git a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java index 10a5989bba..71cb5e8602 100644 --- a/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java +++ b/core/src/main/java/bisq/core/trade/statistics/TradeStatistics3.java @@ -182,6 +182,10 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl @Getter private final Map extraDataMap; + // We cache the date object to avoid reconstructing a new Date at each getDate call. + @JsonExclude + private transient final Date dateObj; + public TradeStatistics3(String currency, long price, long amount, @@ -251,6 +255,8 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl this.extraDataMap = ExtraDataMapValidator.getValidatedExtraDataMap(extraDataMap); this.hash = hash == null ? createHash() : hash; + + dateObj = new Date(date); } public byte[] createHash() { @@ -319,7 +325,7 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl @Override public Date getDate() { - return new Date(date); + return dateObj; } public long getDateAsLong() { From f7a706518c08319449f832bde44a61fac6e11964 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 15 Dec 2020 01:03:52 -0500 Subject: [PATCH 4/5] Use PRIVATE_LOW_PRIO instead of PRIVATE for sequenceNumberMap to reduce cpu load for persistence. --- p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java b/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java index 172cae338f..454d942096 100644 --- a/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java +++ b/p2p/src/main/java/bisq/network/p2p/storage/P2PDataStorage.java @@ -177,7 +177,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers networkNode.addMessageListener(this); networkNode.addConnectionListener(this); - this.persistenceManager.initialize(sequenceNumberMap, PersistenceManager.Source.PRIVATE); + this.persistenceManager.initialize(sequenceNumberMap, PersistenceManager.Source.PRIVATE_LOW_PRIO); } From 7e145739c3028f1245a7a878bf86679235cfc081 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Tue, 15 Dec 2020 01:05:16 -0500 Subject: [PATCH 5/5] Cache hash to avoid expensive hash operation. --- .../java/bisq/core/dao/state/model/governance/Role.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/state/model/governance/Role.java b/core/src/main/java/bisq/core/dao/state/model/governance/Role.java index c0b7079e0c..4850b31541 100644 --- a/core/src/main/java/bisq/core/dao/state/model/governance/Role.java +++ b/core/src/main/java/bisq/core/dao/state/model/governance/Role.java @@ -46,6 +46,9 @@ public final class Role implements PersistablePayload, NetworkPayload, BondedAss private final String link; private final BondedRoleType bondedRoleType; + // Only used as cache + transient private final byte[] hash; + /** * @param name Full name or nickname * @param link GitHub account or forum account of user @@ -74,6 +77,8 @@ public final class Role implements PersistablePayload, NetworkPayload, BondedAss this.name = name; this.link = link; this.bondedRoleType = bondedRoleType; + + hash = Hash.getSha256Ripemd160hash(toProtoMessage().toByteArray()); } @Override @@ -100,8 +105,7 @@ public final class Role implements PersistablePayload, NetworkPayload, BondedAss @Override public byte[] getHash() { - byte[] bytes = toProtoMessage().toByteArray(); - return Hash.getSha256Ripemd160hash(bytes); + return hash; } @Override