From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 391503944401; Mon, 5 Dec 2022 17:57:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 391503944401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670263075; bh=TgHGv5CAHVkcQKXAMMBhSff0Vgu7sStYC16/JeuoyLw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pesxdMBVbfzi5hiKSPwm0wEBGnyb2G8RfNhRcm2GJ6DLwHYD3ASmr3mZl5BubBDMY SY3JtQnCDFSFZPYWgbVQII6V1f5E+dbfRnywKDBppoylyTgueMzJDJCVWpROr0O3f8 alNMJ37w5FvWRhLUGU06s4AmfPcVW+E7zNnpSNdI= From: "jason at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105838] [10/11/12/13 Regression] g++ 12.1.0 runs out of memory or time when building const std::vector of std::strings Date: Mon, 05 Dec 2022 17:57:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: compile-time-hog, memory-hog X-Bugzilla-Severity: normal X-Bugzilla-Who: jason at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105838 Jason Merrill changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED --- Comment #10 from Jason Merrill --- A lot of the problem here is that building a std::string involves building a std::allocator temporary to pass to the string constructor, and then = we need to wait until the entire array is built before we can destroy any of t= hem: https://eel.is/c++draft/class.temporary#5 says we can only destroy temporar= ies early if there was no initializer for that array element. So for each elem= ent of the initializer we have another EH region for its allocator temporary. We could do better for the general case by creating a parallel array of temporaries and using the same single cleanup region for it as for the arra= y of strings. This seems like a worthwhile general optimization. We might be able to do better for the specific case by recognizing that std::allocator has no data and nothing cares about its address, so we can go ahead and destroy it after initializing the string, and reuse the stack slo= t.=20 This also saves stack space.=