From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C5B0B3858D37; Mon, 6 Jul 2020 18:37:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C5B0B3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594060645; bh=9y6xCwniVozOK4HDN0Szc03AbquMvZ9LfXJHQbsa0Bc=; h=From:To:Subject:Date:From; b=B5CKDiYWyMzUARSrXxqCM1Pf7yWUc0kLB+GtdVy/yhxjkiJ6oss7+0p3IF/zZVIt+ F19LwVdW7+eHShculL1/EFZIpAfNxeHXPh7YNvb8FM93mPPeD2EGM9m/EBbDKVIwoM QLmLajOvp7SFapJmaWB8e0jlvZyQIzAVghRUTvyQ= From: "antoshkka at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/96088] New: Range insertion into unordered_map is less effective than a loop with insertion Date: Mon, 06 Jul 2020 18:37:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new 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: antoshkka at gmail dot com 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: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Mon, 06 Jul 2020 18:37:25 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96088 Bug ID: 96088 Summary: Range insertion into unordered_map is less effective than a loop with insertion Product: gcc Version: 11.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Consider the function f1: static constexpr std::initializer_list> lst =3D= { {"long_str_for_dynamic_allocating", 1}}; void f1() { std::unordered_map m(1); m.insert(lst.begin(), lst.end()); } It creates a temporary and as a result makes 4 allocations. Meanwhile f2 do= es not create a temporary and does aonly 3 allocations: void f2() { std::unordered_map m(1); for (const auto& x : lst) { m.insert(x); } } Godbolt playground: https://godbolt.org/z/VapmBU=