You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2020/10/21 18:27:53 UTC

[qpid-proton] branch master updated: PROTON-2229: Try to improve codec performance by reducing unnecessary allocations

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

astitcher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


The following commit(s) were added to refs/heads/master by this push:
     new 07ba43f  PROTON-2229: Try to improve codec performance by reducing unnecessary allocations
07ba43f is described below

commit 07ba43f12d978cbc729cdb56609162351db5ddd8
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Wed Oct 21 14:02:25 2020 -0400

    PROTON-2229: Try to improve codec performance by reducing unnecessary allocations
---
 c/src/core/codec.c | 8 ++++----
 c/src/core/data.h  | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/c/src/core/codec.c b/c/src/core/codec.c
index b50f286..34f9d35 100644
--- a/c/src/core/codec.c
+++ b/c/src/core/codec.c
@@ -434,9 +434,6 @@ static int pni_data_grow(pn_data_t *data)
 
 static ssize_t pni_data_intern(pn_data_t *data, const char *start, size_t size)
 {
-  if (data->buf == NULL) {
-    data->buf = pn_buffer(size);
-  }
   size_t offset = pn_buffer_size(data->buf);
   int err = pn_buffer_append(data->buf, start, size);
   if (err) return err;
@@ -472,7 +469,10 @@ static int pni_data_intern_node(pn_data_t *data, pni_node_t *node)
   pn_bytes_t *bytes = pni_data_bytes(data, node);
   if (!bytes) return 0;
   if (data->buf == NULL) {
-    data->buf = pn_buffer(bytes->size);
+    // Heuristic to avoid growing small buffers too much
+    // size + 1 to allow for zero termination
+    size_t size = pn_max(bytes->size+1, PNI_INTERN_MINSIZE);
+    data->buf = pn_buffer(size);
   }
   size_t oldcap = pn_buffer_capacity(data->buf);
   ssize_t offset = pni_data_intern(data, bytes->start, bytes->size);
diff --git a/c/src/core/data.h b/c/src/core/data.h
index 442760e..59e60d1 100644
--- a/c/src/core/data.h
+++ b/c/src/core/data.h
@@ -29,6 +29,7 @@
 
 typedef uint16_t pni_nid_t;
 #define PNI_NID_MAX ((pni_nid_t)-1)
+#define PNI_INTERN_MINSIZE 64
 
 typedef struct {
   char *start;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org