Return-Path: X-Original-To: apmail-subversion-dev-archive@minotaur.apache.org Delivered-To: apmail-subversion-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 21DC1177A1 for ; Wed, 7 Oct 2015 11:53:46 +0000 (UTC) Received: (qmail 11007 invoked by uid 500); 7 Oct 2015 11:53:45 -0000 Delivered-To: apmail-subversion-dev-archive@subversion.apache.org Received: (qmail 10954 invoked by uid 500); 7 Oct 2015 11:53:45 -0000 Mailing-List: contact dev-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list dev@subversion.apache.org Received: (qmail 10944 invoked by uid 99); 7 Oct 2015 11:53:45 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Oct 2015 11:53:45 +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 21438C41C9 for ; Wed, 7 Oct 2015 11:53:45 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.121 X-Spam-Level: X-Spam-Status: No, score=-0.121 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id YPdEAjiOlFKl for ; Wed, 7 Oct 2015 11:53:44 +0000 (UTC) Received: from mail-vk0-f46.google.com (mail-vk0-f46.google.com [209.85.213.46]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 9670A25426 for ; Wed, 7 Oct 2015 11:53:43 +0000 (UTC) Received: by vkat63 with SMTP id t63so9022752vka.1 for ; Wed, 07 Oct 2015 04:53:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=HJBI0Yc6d16dmnUBdjUZRKK3Qi77OOmH4+nljf2nuH4=; b=rwL5K9G96N+g3UIWvXfvJPz0EwuyzOE2fCv8UndMlOCUKIIbZ75Ivp6un/fGMTHknX y0RbW6H3gIuX2GBrd25q38COyYCfuFgvl05mzDaks+HXze4QV/gIwILW1ajTce3s7L7L 8XAhloiTktx13JOpV1Pkb4HzZM2YN0ig+tfWmnet/Fpxu03TkYBRuwWSY8Rhg+XHjECj ryKAdJaZkxvm5kJJFRGdGnYVXivXVNELGBv+SOflediJUHrJMPEBGZC8L54AvypzC2lp T+bxDfytgFf/2q2dBS4ECuM3uufCucMUWdciOLmwlXilWxG/Mu4IlLHldMqZ2FpDF9qc I6/Q== X-Received: by 10.31.33.14 with SMTP id h14mr506685vkh.58.1444218822675; Wed, 07 Oct 2015 04:53:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.41.8 with HTTP; Wed, 7 Oct 2015 04:53:23 -0700 (PDT) In-Reply-To: References: <20151007075707.21F4B3A0046@svn01-us-west.apache.org> <4ad801d100f0$8c352820$a49f7860$@qqmail.nl> From: Julian Foad Date: Wed, 7 Oct 2015 12:53:23 +0100 Message-ID: Subject: Re: svn commit: r1707196 - /subversion/trunk/subversion/libsvn_subr/stream.c To: Ivan Zhakov Cc: Bert Huijben , dev Content-Type: text/plain; charset=UTF-8 Ivan Zhakov wrote: > Bert Huijben wrote: >>> URL: http://svn.apache.org/viewvc?rev=1707196&view=rev >>> Log: >>> Slightly optimize svn_stringbuf_from_stream() to avoid allocating twice >>> more memory and unnecessary memcpy() when LEN_HINT is equal to final >>> stringbuf >>> length. >>> >>> * subversion/libsvn_subr/stream.c >>> (svn_stringbuf_from_stream): Always preallocate LEN_HINT + >>> MIN_READ_SIZE >>> bytes to be able perform final read without stringbuf reallocation. >> >> Can you explain why hint + MIN_READ_SIZE instead of something like >> MAX(len_hint+1, MIN_READ_SIZE) >> >> I don't know what MIN_READ_SIZE is from just this patch, but it could easily be >> something like 16 Kbyte, while len_hint could be something like 16 for a file like >> 'format' that was just statted to obtain the actual size >> >> 16 Kbyte + 16 bytes for a 16 bytes file looks a bit large... And allocating 16 + 32 >> bytes is far more efficient than allocating that huge chunk at once. >> > MIN_READ_SIZE is 64 bytes and it's locally defined in this function. > We cannot use MAX(len_hint+1, MIN_READ_SIZE) because main loop > reallocates buffer if don't have MIN_READ_SIZE remaining. The current > code assumes that MIN_READ_SIZE is small value and I decided to leave > this code intact. It could be improved of course, but I wanted to make > minimum change first. I don't think that was the right fix. One deficiency with the code is that it doesn't break out of the loop when end-of-stream is detected, which can be reported by a 'short' read. Your change doesn't solve that problem in general, although it does solve it for the case where the supplied length hint is exactly right. We also have the function svn_string_from_stream() which performs a virtually identical task. These two functions have completely different implementations. svn_string_from_stream() does break out of the loop as soon as it detects end-of-stream reported as a short read. They also use completely different read sizes (MIN_READ_SIZE = 64 bytes vs. SVN__STREAM_CHUNK_SIZE = 16384). That is silly: there is no good reason for that, and it is a waste of effort maintaining them separately, and discussing separate optimizations for each. We should make those two functions share the same "best" implementation. - Julian