[Groonga-commit] groonga/groonga at a6ff19d [master] bulk: reduce the number of realloc()

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Dec 12 09:00:48 JST 2017


Kouhei Sutou	2017-12-12 09:00:48 +0900 (Tue, 12 Dec 2017)

  New Revision: a6ff19d3aa3f9a8fc1f3a7c636543e5824ff1a42
  https://github.com/groonga/groonga/commit/a6ff19d3aa3f9a8fc1f3a7c636543e5824ff1a42

  Message:
    bulk: reduce the number of realloc()
    
    It improves performance for large output case on Windows. For example,
    it causes 100x faster for 100MB over output.
    
    Because realloc() is heavy on Windows. FYI: realloc() is cheap on Linux.

  Modified files:
    lib/str.c

  Modified: lib/str.c (+7 -1)
===================================================================
--- lib/str.c    2017-12-11 09:47:22 +0900 (ab720cdb0)
+++ lib/str.c    2017-12-12 09:00:48 +0900 (c99d11368)
@@ -1960,7 +1960,13 @@ grn_bulk_write(grn_ctx *ctx, grn_obj *buf, const char *str, unsigned int len)
   grn_rc rc = GRN_SUCCESS;
   char *curr;
   if (GRN_BULK_REST(buf) < len) {
-    if ((rc = grn_bulk_resize(ctx, buf, GRN_BULK_VSIZE(buf) + len))) { return rc; }
+    unsigned int new_size = GRN_BULK_VSIZE(buf) + len;
+    if (GRN_BULK_OUTP(buf) ||
+        (new_size + grn_bulk_margin_size + 1) > GRN_BULK_BUFSIZE ||
+        new_size < (UINT32_MAX / 2)) {
+      new_size *= 2;
+    }
+    if ((rc = grn_bulk_resize(ctx, buf, new_size))) { return rc; }
   }
   curr = GRN_BULK_CURR(buf);
   grn_memcpy(curr, str, len);
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171212/608faee4/attachment.htm 



More information about the Groonga-commit mailing list
Back to archive index