You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/03/16 01:18:30 UTC

[james-project] branch master updated (aa253c8 -> 06a693b)

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from aa253c8  JAMES-3724 - Document Leak detection mode
     new 3c7cb4a  [PERF] Improves performance of IdRange::toString of 50%
     new 16afc8a  [PERF] IMAP SELECT decoding should not rely on exception
     new 30e6433  [PERF] Avoid calling toString on IMAP commands if not strictly needed
     new 77f3674  [PERF] DefaultImapDecoder should avoid needless map writes
     new c295b24  [PERF] FetchGroupConverter can optimize single element
     new 6eba433  [PERF] MDCBuilder: optimize when 'flat'
     new 9b91068  [PERF] ResultUtils::haveValidContent should avoid stream operation
     new 317bf5c  [PERF] SelectedMailboxImpl: avoid needless copies
     new 7e2b0da  [PERF] StatusResponseEncoder: Use String::isEmpty
     new 134257c  [PERF] StoreMessageManager::resetRecents send events only if needed
     new 06a693b  [PERF] FetchData::toString avoid a needless copy

The 11 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/james/mailbox/store/ResultUtils.java   |  4 +---
 .../james/mailbox/store/StoreMessageManager.java      | 19 ++++++++++---------
 .../james/mailbox/store/mail/FetchGroupConverter.java |  8 +++++++-
 .../org/apache/james/imap/api/message/FetchData.java  |  4 ++--
 .../org/apache/james/imap/api/message/IdRange.java    | 12 +++++++-----
 .../james/imap/decode/ImapRequestLineReader.java      | 15 +++++++++++++++
 .../james/imap/decode/main/DefaultImapDecoder.java    |  5 ++++-
 .../decode/parser/AbstractSelectionCommandParser.java | 10 +++-------
 .../james/imap/encode/StatusResponseEncoder.java      |  2 +-
 .../imap/processor/base/AbstractChainedProcessor.java |  4 +++-
 .../imap/processor/base/SelectedMailboxImpl.java      |  8 +++-----
 .../main/java/org/apache/james/util/MDCBuilder.java   | 10 ++++++----
 12 files changed, 62 insertions(+), 39 deletions(-)

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 09/11: [PERF] StatusResponseEncoder: Use String::isEmpty

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 7e2b0da9bb76baa5b454c5954c5d1c245e825939
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 11 09:23:21 2022 +0700

    [PERF] StatusResponseEncoder: Use String::isEmpty
    
    Cheaper, simpler.
---
 .../main/java/org/apache/james/imap/encode/StatusResponseEncoder.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/StatusResponseEncoder.java b/protocols/imap/src/main/java/org/apache/james/imap/encode/StatusResponseEncoder.java
index 45aae42..89498b9 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/encode/StatusResponseEncoder.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/encode/StatusResponseEncoder.java
@@ -97,7 +97,7 @@ public class StatusResponseEncoder implements ImapResponseEncoder<ImmutableStatu
         if (command != null) {
             composer.commandName(command);
         }
-        if (text != null && !"".equals(text)) {
+        if (text != null && !text.isEmpty()) {
             composer.message(text);
         }
         composer.end();

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 11/11: [PERF] FetchData::toString avoid a needless copy

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 06a693b11284e49b5dee948a5e3677fe29f6e473
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 11 09:26:16 2022 +0700

    [PERF] FetchData::toString avoid a needless copy
    
    We are already working with an immutable collection, no need to copy it.
---
 .../src/main/java/org/apache/james/imap/api/message/FetchData.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java
index 822dfa2..047387b 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/FetchData.java
@@ -106,7 +106,7 @@ public class FetchData {
     }
 
     private final EnumSet<Item> itemToFetch;
-    private final Set<BodyFetchElement> bodyElements;
+    private final ImmutableSet<BodyFetchElement> bodyElements;
     private final boolean setSeen;
     private final long changedSince;
     private final boolean vanished;
@@ -181,7 +181,7 @@ public class FetchData {
             .add("body", contains(Item.BODY))
             .add("bodyStructure", contains(Item.BODY_STRUCTURE))
             .add("setSeen", setSeen)
-            .add("bodyElements", ImmutableSet.copyOf(bodyElements))
+            .add("bodyElements", bodyElements)
             .add("modSeq", contains(Item.MODSEQ))
             .add("changedSince", changedSince)
             .add("vanished", vanished)

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 01/11: [PERF] Improves performance of IdRange::toString of 50%

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 3c7cb4a6fbef9049ed3a80084055b3255e5121b0
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 10 15:59:47 2022 +0700

    [PERF] Improves performance of IdRange::toString of 50%
---
 .../main/java/org/apache/james/imap/api/message/IdRange.java | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/message/IdRange.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/IdRange.java
index 106f4f0..410c75b 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/message/IdRange.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/IdRange.java
@@ -20,16 +20,16 @@
 package org.apache.james.imap.api.message;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 import org.apache.james.mailbox.model.MessageRange;
 
-import com.google.common.collect.ImmutableList;
-
 /**
  * Represents a range of UID or MSN values.
  */
@@ -108,9 +108,11 @@ public final class IdRange implements Iterable<Long>, Comparable<IdRange> {
     }
 
     public static String toString(IdRange[] ranges) {
-        return Optional.ofNullable(ranges)
-            .map(ImmutableList::copyOf)
-            .toString();
+        return "(" + Optional.ofNullable(ranges)
+            .map(array -> Arrays.stream(array)
+                .map(IdRange::toString)
+                .collect(Collectors.joining(",")))
+            .orElse("") + ")";
     }
 
     public static IdRange from(MessageRange messageRange) {

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 10/11: [PERF] StoreMessageManager::resetRecents send events only if needed

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 134257c5fc1fd7c9d8c40aec77274dc6bd5fc1c5
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 11 09:25:22 2022 +0700

    [PERF] StoreMessageManager::resetRecents send events only if needed
    
    If there is no recents we don't want to:
     - generate an eventId
     - Instanciate the event
     - Pay a scheduling price (block)
    
    Also we don't need to switch this call to another scheduler, current
    thread is fine.
---
 .../james/mailbox/store/StoreMessageManager.java      | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index a3186c3..692f5e2 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -752,15 +752,16 @@ public class StoreMessageManager implements MessageManager {
 
         List<UpdatedFlags> updatedFlags = messageMapper.resetRecent(getMailboxEntity());
 
-        eventBus.dispatch(EventFactory.flagsUpdated()
-                .randomEventId()
-                .mailboxSession(mailboxSession)
-                .mailbox(getMailboxEntity())
-                .updatedFlags(updatedFlags)
-                .build(),
-            new MailboxIdRegistrationKey(mailbox.getMailboxId()))
-            .subscribeOn(Schedulers.elastic())
-            .block();
+        if (!updatedFlags.isEmpty()) {
+            eventBus.dispatch(EventFactory.flagsUpdated()
+                    .randomEventId()
+                    .mailboxSession(mailboxSession)
+                    .mailbox(getMailboxEntity())
+                    .updatedFlags(updatedFlags)
+                    .build(),
+                new MailboxIdRegistrationKey(mailbox.getMailboxId()))
+                .block();
+        }
 
         return updatedFlags.stream()
             .map(UpdatedFlags::getUid)

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 04/11: [PERF] DefaultImapDecoder should avoid needless map writes

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 77f3674cb8834c984b70223e59462a9d420a63b7
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 11 08:43:34 2022 +0700

    [PERF] DefaultImapDecoder should avoid needless map writes
    
    Most of the time the value is already 0, overwriting it is costly
---
 .../java/org/apache/james/imap/decode/main/DefaultImapDecoder.java   | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/main/DefaultImapDecoder.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/main/DefaultImapDecoder.java
index cce1b01..523c626 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/main/DefaultImapDecoder.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/main/DefaultImapDecoder.java
@@ -112,7 +112,10 @@ public class DefaultImapDecoder implements ImapDecoder {
             return unknownCommand(tag, session);
         }
         ImapMessage message = command.parse(request, tag, session);
-        session.setAttribute(INVALID_COMMAND_COUNT, 0);
+        Object count = session.getAttribute(INVALID_COMMAND_COUNT);
+        if (count == null || (int) count > 0) {
+            session.setAttribute(INVALID_COMMAND_COUNT, 0);
+        }
         return message;
     }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 03/11: [PERF] Avoid calling toString on IMAP commands if not strictly needed

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 30e643339b693190f725798144c21a9e574f4d37
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 11 08:42:13 2022 +0700

    [PERF] Avoid calling toString on IMAP commands if not strictly needed
---
 .../apache/james/imap/processor/base/AbstractChainedProcessor.java    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/AbstractChainedProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/AbstractChainedProcessor.java
index 9eaf492..448eeb2 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/AbstractChainedProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/AbstractChainedProcessor.java
@@ -54,7 +54,9 @@ public abstract class AbstractChainedProcessor<M extends ImapMessage> implements
             M acceptableMessage = (M) message;
             try (Closeable closeable = addContextToMDC(acceptableMessage)) {
                 try {
-                    LOGGER.debug("Processing {}", message.toString());
+                    if (LOGGER.isDebugEnabled()) {
+                        LOGGER.debug("Processing {}", message.toString());
+                    }
                     doProcess(acceptableMessage, responder, session);
                 } catch (RuntimeException e) {
                     LOGGER.error("Error while processing IMAP request", e);

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 06/11: [PERF] MDCBuilder: optimize when 'flat'

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 6eba4337a6ba6e44366ce0648c9349a23fa54e8d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 11 09:16:58 2022 +0700

    [PERF] MDCBuilder: optimize when 'flat'
    
    Most of our MDCs are 'flat', without nesting other MDC builders, yet
    in MDC builder we keep an additional ImmutableMap builder to handle
    nested elements even when it is 'flat'.
    
    When flat building directly this MDC internals result in a 50% gain.
    
    The memory James server spend 20% of its time building MDCs...
---
 .../util/src/main/java/org/apache/james/util/MDCBuilder.java   | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/server/container/util/src/main/java/org/apache/james/util/MDCBuilder.java b/server/container/util/src/main/java/org/apache/james/util/MDCBuilder.java
index 4e86ecc..bff52f2 100644
--- a/server/container/util/src/main/java/org/apache/james/util/MDCBuilder.java
+++ b/server/container/util/src/main/java/org/apache/james/util/MDCBuilder.java
@@ -146,11 +146,13 @@ public class MDCBuilder {
 
     @VisibleForTesting
     Map<String, String> buildContextMap() {
-        ImmutableMap.Builder<String, String> result = ImmutableMap.builder();
-
-        nestedBuilder.build()
-            .forEach(mdcBuilder -> result.putAll(mdcBuilder.buildContextMap()));
+        ImmutableList<MDCBuilder> nested = nestedBuilder.build();
+        if (nested.isEmpty()) {
+            return contextMap.build();
+        }
 
+        ImmutableMap.Builder<String, String> result = ImmutableMap.builder();
+        nested.forEach(mdcBuilder -> result.putAll(mdcBuilder.buildContextMap()));
         return result
             .putAll(contextMap.build())
             .build();

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 02/11: [PERF] IMAP SELECT decoding should not rely on exception

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 16afc8a0e308e458755dcd1061bb0b93302e56e7
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 10 16:01:37 2022 +0700

    [PERF] IMAP SELECT decoding should not rely on exception
    
    Filling the stacktrace for this represents 30% of decoding
    time of a workload of repeat(SELECT, FETCH)...
---
 .../apache/james/imap/decode/ImapRequestLineReader.java   | 15 +++++++++++++++
 .../decode/parser/AbstractSelectionCommandParser.java     | 10 +++-------
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
index 25a32cc..045ebec 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
@@ -34,6 +34,7 @@ import java.nio.charset.CodingErrorAction;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 
 import javax.mail.Flags;
 
@@ -93,6 +94,20 @@ public abstract class ImapRequestLineReader {
         return next;
     }
 
+    public Optional<Character> nextWordCharLenient() throws DecodingException {
+        char next = nextChar();
+        while (next == ' ') {
+            consume();
+            next = nextChar();
+        }
+
+        if (next == '\r' || next == '\n') {
+            return Optional.empty();
+        }
+
+        return Optional.of(next);
+    }
+
     /**
      * Reads the next character in the current line. This method will continue
      * to return the same character until the {@link #consume()} method is
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
index 5014107..8959299 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
@@ -52,13 +52,9 @@ public abstract class AbstractSelectionCommandParser extends AbstractImapCommand
         UidRange[] uidSet = null;
         UidRange[] knownUidSet = null;
         IdRange[] knownSequenceSet = null;
-        
-        char c = Character.UNASSIGNED;
-        try {
-            c = request.nextWordChar();
-        } catch (DecodingException e) {
-            // This is expected if the request has no options like CONDSTORE and QRESYNC
-        }
+
+        char c = request.nextWordCharLenient()
+            .orElse((char) Character.UNASSIGNED);
         
         // Ok an option was found
         if (c == '(') {

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 05/11: [PERF] FetchGroupConverter can optimize single element

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit c295b24ada4f8084ca4e3cd0d73f375a403a0072
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 11 08:49:36 2022 +0700

    [PERF] FetchGroupConverter can optimize single element
---
 .../org/apache/james/mailbox/store/mail/FetchGroupConverter.java  | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
index 1b70241..112775c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/FetchGroupConverter.java
@@ -20,6 +20,7 @@
 package org.apache.james.mailbox.store.mail;
 
 import java.util.Collection;
+import java.util.EnumSet;
 
 import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.mailbox.model.FetchGroup;
@@ -37,7 +38,12 @@ public class FetchGroupConverter {
             return MessageMapper.FetchType.FULL;
         }
 
-        Collection<MessageMapper.FetchType> fetchTypes = group.profiles()
+        EnumSet<Profile> profiles = group.profiles();
+        if (profiles.size() == 1) {
+            return toFetchType(profiles.iterator().next());
+        }
+
+        Collection<MessageMapper.FetchType> fetchTypes = profiles
             .stream()
             .map(FetchGroupConverter::toFetchType)
             .collect(ImmutableList.toImmutableList());

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 07/11: [PERF] ResultUtils::haveValidContent should avoid stream operation

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 9b91068643a16edea62da7807848d2b65d23837c
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 11 09:19:35 2022 +0700

    [PERF] ResultUtils::haveValidContent should avoid stream operation
    
    Streams can be costly and sonarlint proposed me an equivalent refactoring
    relying only on native methods...
    
    2.5% of FETCH time was spent in this method...
---
 .../src/main/java/org/apache/james/mailbox/store/ResultUtils.java     | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
index 2066469..db7bf04 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/ResultUtils.java
@@ -117,9 +117,7 @@ public class ResultUtils {
 
     @VisibleForTesting
     static boolean haveValidContent(FetchGroup fetchGroup) {
-        return fetchGroup.profiles()
-            .stream()
-            .allMatch(SUPPORTED_GROUPS::contains);
+        return SUPPORTED_GROUPS.containsAll(fetchGroup.profiles());
     }
 
     private static void addPartContent(FetchGroup fetchGroup, MailboxMessage message, MessageResultImpl messageResult)

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 08/11: [PERF] SelectedMailboxImpl: avoid needless copies

Posted by bt...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 317bf5c21d48638ae0500939e233db87c77c94c8
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 11 09:22:44 2022 +0700

    [PERF] SelectedMailboxImpl: avoid needless copies
    
    Copy a treeset into a treeset then make it non-modifiable...
---
 .../org/apache/james/imap/processor/base/SelectedMailboxImpl.java | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
index 077d93d..2b3aa92 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
@@ -26,7 +26,6 @@ import static io.vavr.Predicates.instanceOf;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Optional;
@@ -63,6 +62,7 @@ import org.apache.james.mailbox.model.UpdatedFlags;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSortedSet;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -338,8 +338,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, EventListener {
         // copy the TreeSet to fix possible
         // java.util.ConcurrentModificationException
         // See IMAP-278
-        return Collections.unmodifiableSet(new TreeSet<>(flagUpdateUids));
-        
+        return ImmutableSortedSet.copyOf(flagUpdateUids);
     }
 
     @Override
@@ -347,8 +346,7 @@ public class SelectedMailboxImpl implements SelectedMailbox, EventListener {
         // copy the TreeSet to fix possible
         // java.util.ConcurrentModificationException
         // See IMAP-278
-        return Collections.unmodifiableSet(new TreeSet<>(expungedUids));
-        
+        return ImmutableSortedSet.copyOf(expungedUids);
     }
 
     @Override

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org