From patchwork Wed Nov 7 22:02:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 197731 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 1F3902C00AE for ; Thu, 8 Nov 2012 09:02:53 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1352930575; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=JKv+NdbOwEx2hJAQuZmQHTfdM28=; b=B9UPALJ+k6kH6APPFWIef3vYpBVfEUOvTGOZ4osv/7Okgh5NlviCc/c1a7m6od QLbfxaDJjsqNsljcOq1atwNGnNPPMPa9Ys7ougl+cOdGiHEP/wxuWWGlY5Gm48tL da9v06mfj2vLmy0qeqf28PAmJ1/zgY/6RoHTNp2JwpNqU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=gJZZUgATZGehwL4WIbBPqcv/JlnSWFBeFWeb+2bNFllqbIqhTVwQerHkwIvkUv 8+RMjfoXmsabMw6E1FU9ikjl40VN6tg10KZMkdkXSMsBGKJ9ElnCBlqzNmiqQrvy 3tbr/lJhIQYK3EltbppnVsiyNCbtQ3CRRfwuJLSZ3S6+g=; Received: (qmail 14966 invoked by alias); 7 Nov 2012 22:02:49 -0000 Received: (qmail 14949 invoked by uid 22791); 7 Nov 2012 22:02:48 -0000 X-SWARE-Spam-Status: No, hits=-5.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-wg0-f41.google.com (HELO mail-wg0-f41.google.com) (74.125.82.41) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 07 Nov 2012 22:02:42 +0000 Received: by mail-wg0-f41.google.com with SMTP id ds1so3541768wgb.2 for ; Wed, 07 Nov 2012 14:02:41 -0800 (PST) Received: by 10.216.226.98 with SMTP id a76mr2674366weq.5.1352325761271; Wed, 07 Nov 2012 14:02:41 -0800 (PST) Received: from localhost.localdomain (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by mx.google.com with ESMTPS id hf10sm5355208wib.0.2012.11.07.14.02.38 (version=SSLv3 cipher=OTHER); Wed, 07 Nov 2012 14:02:39 -0800 (PST) Message-ID: <509ADA7E.7050504@gmail.com> Date: Wed, 07 Nov 2012 23:02:38 +0100 From: =?UTF-8?B?RnJhbsOnb2lzIER1bW9udA==?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120829 Thunderbird/15.0 MIME-Version: 1.0 To: "paolo.carlini at oracle dot com" CC: "libstdc++@gcc.gnu.org" , gcc-patches Subject: Re: [Bug libstdc++/54075] [4.7.1] unordered_map insert still slower than 4.6.2 References: In-Reply-To: Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Here is the patch to fix the redundant rehash/reserve issue. 2012-11-07 François Dumont PR libstdc++/54075 * include/bits/hashtable.h (_Hashtable<>::rehash): Reset hash policy state if no rehash. * testsuite/23_containers/unordered_set/modifiers/reserve.cc (test02): New. I had prepared and tested it in 4.7 branch but I can apply the same on trunk. Ok to commit ? If so, where ? François On 11/06/2012 10:33 PM, paolo.carlini at oracle dot com wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54075 > > --- Comment #39 from Paolo Carlini 2012-11-06 21:33:57 UTC --- > Ok thanks. I guess depending on the complexity of the fixes we can apply some > only to mainline first and reconsider the 4_7 branch later. Please do your best > to work on both issues: we just entered Stage 3 thus no new features from now > on, we are all concentrated on bug fixes until the release. > Index: include/bits/hashtable.h =================================================================== --- include/bits/hashtable.h (revision 193258) +++ include/bits/hashtable.h (working copy) @@ -1597,6 +1597,9 @@ // level. _M_rehash_policy._M_prev_resize = 0; } + else + // No rehash, restore previous state to keep a consistent state. + _M_rehash_policy._M_reset(__saved_state); } template Set; + Set s; + s.reserve(N); + s.reserve(N); + + std::size_t bkts = s.bucket_count(); + for (int i = 0; i != N; ++i) + { + s.insert(i); + // As long as we insert less than the reserved number of elements we + // shouldn't experiment any rehash. + VERIFY( s.bucket_count() == bkts ); + } +} + int main() { test01(); + test02(); return 0; }