From: Ramsay Jones Subject: [PATCH v3 0/2] alloc.c: remove alloc_raw_commit_node() function Date: Fri, 11 Jul 2014 00:57:11 +0100 Message-ID: <53BF2857.8000603@ramsay1.demon.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Junio C Hamano , GIT Mailing-list To: Jeff King X-From: git-owner@vger.kernel.org Fri Jul 11 01:57:25 2014 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1X5ODI-0000Dq-Dq for gcvg-git-2@plane.gmane.org; Fri, 11 Jul 2014 01:57:20 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751352AbaGJX5R (ORCPT ); Thu, 10 Jul 2014 19:57:17 -0400 Received: from mdfmta010.mxout.tbr.inty.net ([91.221.168.51]:58679 "EHLO smtp.demon.co.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751011AbaGJX5Q (ORCPT ); Thu, 10 Jul 2014 19:57:16 -0400 Received: from mdfmta010.tbr.inty.net (unknown [127.0.0.1]) by mdfmta010.tbr.inty.net (Postfix) with ESMTP id EECB56F8F77; Thu, 10 Jul 2014 23:21:51 +0100 (BST) Received: from mdfmta010.tbr.inty.net (unknown [127.0.0.1]) by mdfmta010.tbr.inty.net (Postfix) with ESMTP id B72C36F8EE1; Thu, 10 Jul 2014 23:21:51 +0100 (BST) Received: from [192.168.254.1] (unknown [80.176.147.220]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mdfmta010.tbr.inty.net (Postfix) with ESMTP; Thu, 10 Jul 2014 23:21:50 +0100 (BST) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 X-MDF-HostID: 3 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Hi Jeff, Another attempt to remove this intermediate allocator. ;-) I didn't think I would like this approach before I started to look at doing this patch, but now I think I rather like it! The first patch uses an inline function (alloc_node()) to implement the allocators, redefining the macro to declare the allocators to, basically: static struct alloc_state something_state; void *alloc_something_node(void) { return alloc_node(&something_state, sizeof(struct something)); } Then alloc_commit_node() can also use the alloc_node() function in its implementation. I checked that the alloc_node() function was actually inlined by gcc, which it was for -O1 -> -O3 (but not for -O0, obviously). The generated assembler looked very similar (but not identical) to the code generated without this patch. Also, I did a quick (and admittedly unsophisticated) performance test. I could not detect any difference, within the noise level of the timings, between the two. (Also, operf barely registered any samples against the alloc functions, for './git log -p >/dev/null'). I also checked the assembler generated by clang, and the story was _almost_ the same. For -O2 -> -O3, clang produced very similar results to gcc. For -O1, clang didn't inline alloc_node(), but used it as a 'leaf' function; the blob allocator function 'fell into' alloc_node() and the other DEFINE-ed allocators 'jmp'-ed to alloc_node() rather than call-ing it. The alloc_commit_node() allocator did actually call alloc_node(). (probably because it was more complicated than a single return ...). Note this was tested (on 32-bit Linux Mint 17) with gcc 4.8.2 and clang 3.4. (Other compilers probably will behave differently ...) The second patch is just a minor clean-up and could be squashed into the first patch. (NOTE: I assume that you want c->index to start at zero; if not ...) ATB, Ramsay Jones Ramsay Allan Jones (2): alloc.c: remove the alloc_raw_commit_node() function alloc.c: remove the redundant commit_count variable alloc.c | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) -- 2.0.0