]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
ZSTD CLI: Use buffered output for improved performance 2985/head
authorYonatan Komornik <yoniko@gmail.com>
Fri, 7 Jan 2022 23:55:19 +0000 (15:55 -0800)
committerYonatan Komornik <yoniko@gmail.com>
Sat, 8 Jan 2022 01:10:13 +0000 (17:10 -0800)
programs/fileio.c

index 379d334eb02077b730a99e92214c3649b4116395..9945daa46d4462cf9cd2047d9ddd79d69b431ab8 100644 (file)
@@ -718,6 +718,17 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
         if (f == NULL) {
             DISPLAYLEVEL(1, "zstd: %s: %s\n", dstFileName, strerror(errno));
         }
+        /* An increased buffer size can provide a significant performance boost on some platforms.
+         * Note that providing a NULL buf with a size that's not 0 is not defined in ANSI C, but is defined
+         * in an extension. There are three possibilities here -
+         * 1. Libc supports the extended version and everything is good.
+         * 2. Libc ignores the size when buf is NULL, in which case everything will continue as if we didn't
+         *    call `setvbuf`.
+         * 3. We fail the call and execution continues but a warning message might be shown.
+         * In all cases due execution continues. For now, I believe that this is a more cost-effective
+         * solution than managing the buffers allocations ourselves (will require an API change). */
+        if(setvbuf(f, NULL, _IOFBF, 1 MB))
+            DISPLAYLEVEL(2, "Warning: setvbuf failed for %s\n", dstFileName);
         return f;
     }
 }