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/05/19 06:33:44 UTC

[james-project] 01/04: [PERF] CassandraMessageDAOV3: Size is known upon header copy

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 cc247bcb467fac39c09984497023a03262070074
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon May 16 10:43:25 2022 +0700

    [PERF] CassandraMessageDAOV3: Size is known upon header copy
    
    Specifying the size enable a clean copy directly in the
    resulting byte array, avoiding an extra copy to an
    intermediate byte array.
    
    Also avoids sizing issue of the byte array that yields
    extra copies and.
    
    Also prevent allocation of the copy buffer that might
    have a non negligible impact for small payloads as is
    often the case with headers.
    
    CassandraMessageDAOV3::saveContent header copy was
    responsible of 1% of total memory allocation.
---
 .../apache/james/mailbox/cassandra/mail/CassandraMessageDAOV3.java   | 2 +-
 .../org/apache/james/mailbox/store/MessageIdManagerTestSystem.java   | 5 +++--
 .../james/mailbox/store/ThreadIdGuessingAlgorithmContract.java       | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOV3.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOV3.java
index acaefa5da8..076bc88953 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOV3.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAOV3.java
@@ -220,7 +220,7 @@ public class CassandraMessageDAOV3 {
 
     private Mono<Tuple2<BlobId, BlobId>> saveContent(MailboxMessage message) throws MailboxException {
         try {
-            byte[] headerContent = IOUtils.toByteArray(message.getHeaderContent());
+            byte[] headerContent = IOUtils.toByteArray(message.getHeaderContent(), message.getHeaderOctets());
             ByteSource bodyByteSource = new ByteSource() {
                 @Override
                 public InputStream openStream() {
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
index 5a6a8a1a77..fd0e814555 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MessageIdManagerTestSystem.java
@@ -43,7 +43,7 @@ import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 
 public class MessageIdManagerTestSystem {
-    private static final byte[] MESSAGE_CONTENT = "subject: any\n\nbody".getBytes(StandardCharsets.UTF_8);
+    private static final byte[] MESSAGE_CONTENT = "subject: any\r\n\r\nbody".getBytes(StandardCharsets.UTF_8);
     public static final ModSeq MOD_SEQ = ModSeq.of(452);
 
     private final MessageIdManager messageIdManager;
@@ -115,7 +115,8 @@ public class MessageIdManagerTestSystem {
     }
 
     private static MailboxMessage createMessage(MailboxId mailboxId, Flags flags, MessageId messageId, ThreadId threadId, MessageUid uid) {
-        MailboxMessage mailboxMessage = new SimpleMailboxMessage(messageId, threadId, new Date(), MESSAGE_CONTENT.length, 1256,
+        int bodyStartOctet = 20;
+        MailboxMessage mailboxMessage = new SimpleMailboxMessage(messageId, threadId, new Date(), MESSAGE_CONTENT.length, bodyStartOctet,
             new ByteContent(MESSAGE_CONTENT), flags, new PropertyBuilder().build(), mailboxId);
         mailboxMessage.setModSeq(MOD_SEQ);
         mailboxMessage.setUid(uid);
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/ThreadIdGuessingAlgorithmContract.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/ThreadIdGuessingAlgorithmContract.java
index f773af894c..1e642f8f78 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/ThreadIdGuessingAlgorithmContract.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/ThreadIdGuessingAlgorithmContract.java
@@ -319,7 +319,7 @@ public abstract class ThreadIdGuessingAlgorithmContract {
     private SimpleMailboxMessage createMessage(Mailbox mailbox, ThreadId threadId) {
         MessageId messageId = messageIdFactory.generate();
         String content = "Some content";
-        int bodyStart = 16;
+        int bodyStart = 12;
         return new SimpleMailboxMessage(messageId,
             threadId,
             new Date(),


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