From issues-return-65836-archive-asf-public=cust-asf.ponee.io@commons.apache.org Wed Jan 10 10:49:07 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id DCF4B18076D for ; Wed, 10 Jan 2018 10:49:07 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id CC852160C23; Wed, 10 Jan 2018 09:49:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EBD16160C40 for ; Wed, 10 Jan 2018 10:49:06 +0100 (CET) Received: (qmail 53276 invoked by uid 500); 10 Jan 2018 09:49:06 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 53265 invoked by uid 99); 10 Jan 2018 09:49:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Jan 2018 09:49:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 90C62C35BA for ; Wed, 10 Jan 2018 09:49:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.911 X-Spam-Level: X-Spam-Status: No, score=-99.911 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id S_Kjm1ulktMs for ; Wed, 10 Jan 2018 09:49:04 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 24F7560EFC for ; Wed, 10 Jan 2018 09:49:03 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 66487E25E0 for ; Wed, 10 Jan 2018 09:49:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 724A6274DD for ; Wed, 10 Jan 2018 09:49:00 +0000 (UTC) Date: Wed, 10 Jan 2018 09:49:00 +0000 (UTC) From: "Stefan Bodewig (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (COMPRESS-438) ZipFile should create a buffered input stream for decoders inside getInputStream(ZipArchiveEntry) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/COMPRESS-438?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Stefan Bodewig updated COMPRESS-438: ------------------------------------ Component/s: Compressors > ZipFile should create a buffered input stream for decoders inside getInputStream(ZipArchiveEntry) > ------------------------------------------------------------------------------------------------- > > Key: COMPRESS-438 > URL: https://issues.apache.org/jira/browse/COMPRESS-438 > Project: Commons Compress > Issue Type: Improvement > Components: Compressors > Reporter: Dawid Weiss > Priority: Minor > Labels: zip > Fix For: 1.16 > > Attachments: Check.java > > > When decoders read from a raw underlying stream (such as a file channel), the performance can degrade an order of magnitude compared to the case when there's a simple buffer in between the physical data source and the codec. > See COMPRESS-380 for an example of this. > The API of {{ZipFile}} is straightforward and tempting enough that blocks of code such as: > {code} > try (ZipFile zfile = new ZipFile("/path/to/zip.zip")) { > Enumeration entries = zfile.getEntries(); > while (entries.hasMoreElements()) { > ZipArchiveEntry e = entries.nextElement(); > try (InputStream is = zfile.getInputStream(e)) { > // do something with is > } > } > } > {code} > seem perfectly justified. The above code suffers from severe performance degradation compared to prebuffered input. Severe means *severe*. Here are some stats from running a snippet of code similar to the above to "just decompress" the same input (~80mb) compressed with different methods. > {code} > # Input compressed with 7za. > 7za a -mm=deflate archive-deflate.zip input > 7za a -mm=deflate64 archive-deflate64.zip input > 7za a -mm=bzip2 archive-bzip2.zip input > {code} > Current master branch: > {code} > # Direct BoundedInputStream > archive-deflate.zip 0.39 sec., 37,893,785 archived => 81,502,941 decompressed > archive-deflate64.zip 26.98 sec., 37,856,848 archived => 81,502,941 decompressed > archive-bzip2.zip 49.16 sec., 38,166,089 archived => 81,502,941 decompressed > {code} > And a simple patch wrapping BoundedInputStream with a BufferedInputStream (deflate64 and bzip2 only, deflate uses java's internal inflater and it prebuffers stuff internally). > {code} > # wrapped with BufferedInputStream, bufferSize = 512 > archive-deflate.zip 0.38 sec., 37,893,785 archived => 81,502,941 decompressed > archive-deflate64.zip 0.95 sec., 37,856,848 archived => 81,504,783 decompressed > archive-bzip2.zip 3.00 sec., 38,166,089 archived => 81,502,941 decompressed > # wrapped with BufferedInputStream, bufferSize = 1024 > archive-deflate.zip 0.41 sec., 37,893,785 archived => 81,502,941 decompressed > archive-deflate64.zip 0.97 sec., 37,856,848 archived => 81,504,783 decompressed > archive-bzip2.zip 2.95 sec., 38,166,089 archived => 81,502,941 decompressed > # wrapped with BufferedInputStream, bufferSize = 4096 > archive-deflate.zip 0.42 sec., 37,893,785 archived => 81,502,941 decompressed > archive-deflate64.zip 0.89 sec., 37,856,848 archived => 81,504,783 decompressed > archive-bzip2.zip 2.97 sec., 38,166,089 archived => 81,502,941 decompressed > {code} > The difference should be evident, even with a tiny buffer of 512 bytes. To put this into perspective on a larger archive: > {code} > archive-deflate.zip 7.68 sec., 1,235,209,977 archived => 1,339,916,520 decompressed > archive-deflate64.zip 784.87 sec., 1,233,470,780 archived => 1,339,916,520 decompressed > {code} > deflate64 improves by ~4900%... > {code} > archive-deflate.zip 8.12 sec., 1,235,209,977 archived => 1,339,916,520 decompressed > archive-deflate64.zip 16.24 sec., 1,233,470,780 archived => 1,339,981,595 decompressed > {code} > I also see that {{ExplodingInputStream}} is already wrapping {{bis}} in a buffered input stream, so I don't see any reason why this shouldn't be done for other compressor streams. An even better patch (to me) would be to modify the constructors of {{Deflate64CompressorInputStream}} and {{BZip2CompressorInputStream}} and add a boolean parameter {{unbuffered}}: then people would know what they're doing when they pass some input stream and {{true}} to such a constructor. The default, single-argument constructor would simply delegate to {{constructor(inputStream, false)}} to ensure an input buffer in between the decoder and the raw stream. > The patch is trivial, so I don't attach it? -- This message was sent by Atlassian JIRA (v6.4.14#64029)