From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 71DE43858D35; Thu, 9 Jul 2020 06:23:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 71DE43858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594275796; bh=CUUsrBRtLbpK3UzZCA2ckezTcaW7LUADOTtaGfz0AOE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=n/NGcZuVt+njOiL8SgTAMLOuBPbIdbbE99itzOqX/pSlziCpLiSagjL3VfXu6TCr2 IXXVPrEqjmu+58S0RPKbo6rtkoUfbgQInf1AjUWOVTvWLY4LDfplq/dxt0lho/O5fO qd+noCRISXljTNY8BI1rSUR+K2jCkLf0FjKtTFxU= From: "fdumont at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/96088] Range insertion into unordered_map is less effective than a loop with insertion Date: Thu, 09 Jul 2020 06:23:16 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: fdumont at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jul 2020 06:23:16 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96088 --- Comment #1 from Fran=C3=A7ois Dumont --- The core issue here is that unordered_map key type is std::string while you insert const char* which explains the temporary. In f2 you use insert(Pair&&) method so a temporary is generated but then mo= ved into the container. In f1 we try to check for insertion before generating t= he value_type and to do so we use hash that generates an addition= al temporary. I'll check if we can be smarter here. A nice improvement would be to change std::hash operator signature to: size_t operator()(const string_view& __str) const noexcept but that's a Standard modification.=