]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Optimize rspamd_fstring_t reallocations
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 9 Dec 2017 13:36:08 +0000 (13:36 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 9 Dec 2017 13:36:08 +0000 (13:36 +0000)
src/libutil/fstring.c
src/plugins/lua/history_redis.lua

index 8b5cae65ba0f84b9a2a91644fd7f11195cebbbb5..65f24dccc7b78ae62bd0b984e866e803d9629f48 100644 (file)
 #include "fstring.h"
 #include "str_util.h"
 
-static const gsize default_initial_size = 48;
+#ifdef WITH_JEMALLOC
+#include <jemalloc/jemalloc.h>
+#endif
+
+static const gsize default_initial_size = 16;
 
 #define fstravail(s) ((s)->allocated - (s)->len)
 
@@ -110,35 +114,12 @@ inline gsize
 rspamd_fstring_suggest_size (gsize len, gsize allocated, gsize needed_len)
 {
        gsize newlen;
-       /* Maximum size when we double the size of new string */
-       static const gsize max_grow = 1024 * 1024;
-
-       newlen = allocated;
-
-       /*
-        * Stop exponential grow at some point, since it might be slow for the
-        * vast majority of cases
-        */
-       if (newlen < max_grow) {
-               newlen *= 2;
-       }
-       else {
-               newlen += max_grow;
-       }
 
-       /*
-        * Check for overflow
-        */
-       if (newlen <= len + needed_len) {
-               newlen = len + needed_len;
+       newlen = MAX (len + needed_len, 1 + allocated * 3 / 2);
 
-               if (newlen < max_grow) {
-                       newlen *= 2;
-               }
-               else {
-                       newlen += max_grow;
-               }
-       }
+#ifdef WITH_JEMALLOC
+       newlen = nallocx (newlen + sizeof (rspamd_fstring_t), 0);
+#endif
 
        return newlen;
 }
index a876b46e75241e12a20cc6d5150921cc9917ca7f..6e26bc06fefe629f5aec33b3e0028db7e6eb7076 100644 (file)
@@ -22,7 +22,7 @@ local redis_params
 
 local settings = {
   key_prefix = 'rs_history', -- default key name
-  nrows = 2000, -- default rows limit
+  nrows = 200, -- default rows limit
   compress = true, -- use zstd compression when storing data in redis
 }