From: Michihiro NAKAJIMA Date: Tue, 9 Aug 2011 14:23:21 +0000 (-0400) Subject: Reduce L1,L2 cache miss in the rar reader. X-Git-Tag: v3.0.0a~158 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8aca0e988d0e306ec8cb178e4222a412d0b0a698;p=thirdparty%2Flibarchive.git Reduce L1,L2 cache miss in the rar reader. A use of large memory(over 1M bytes) for an output buffer makes a lot of cache misses, so we should eliminate it as possible as we can. SVN-Revision: 3578 --- diff --git a/libarchive/archive_read_support_format_rar.c b/libarchive/archive_read_support_format_rar.c index dbfe635ce..d85efa51b 100644 --- a/libarchive/archive_read_support_format_rar.c +++ b/libarchive/archive_read_support_format_rar.c @@ -130,6 +130,14 @@ #define MAX_SYMBOL_LENGTH 0xF #define MAX_SYMBOLS 20 +/* + * Considering L1,L2 cache miss and a calling of write sytem-call, + * the best size of the output buffer(uncompressed buffer) is 128K. + * If the structure of extracting process is changed, this value + * might be researched again. + */ +#define UNP_BUFFER_SIZE (128 * 1024) + /* Define this here for non-Windows platforms */ #if !((defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)) #define FILE_ATTRIBUTE_DIRECTORY 0x10 @@ -1144,9 +1152,7 @@ read_header(struct archive_read *a, struct archive_entry *entry, free(rar->unp_buffer); rar->unp_buffer = NULL; rar->unp_offset = 0; - /* Set a minimum size of an uncompressed buffer. - * This will be over written by a dictionary size */ - rar->unp_buffer_size = 64 * 1024; + rar->unp_buffer_size = UNP_BUFFER_SIZE; memset(rar->lengthtable, 0, sizeof(rar->lengthtable)); __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); rar->ppmd_valid = 0; @@ -2335,8 +2341,6 @@ copy_from_lzss_window(struct archive_read *a, const void **buffer, if (!rar->unp_buffer) { - if (rar->unp_buffer_size < rar->dictionary_size) - rar->unp_buffer_size = rar->dictionary_size; if ((rar->unp_buffer = malloc(rar->unp_buffer_size)) == NULL) { archive_set_error(&a->archive, ENOMEM,