https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102228
Bug ID: 102228 Summary: lookup_anon_field is quadratic Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org Target Milestone: --- When lookup_anon_field is called from build_class_member_access_expr with the intent to build OBJECT.MEMBER in a way including the anon aggregates COMPONENT_REFs then when there is a chain of anon aggregates to cover the path is built bottom-up, repeating the expensive recursive walk of lookup_anon_filed depth-of-anon-aggr times. So instead of building OBJECT.<anon1>.<anon2>....<anonn>.MEMBER by recursing to build_class_member_access_expr first with OBJECT and <anonn> as MEMBER lookup_anon_field should return the full path it found. The PR101555 testcase with -fsyntax-only spends 66% in lookup_anon_field: Samples: 8K of event 'cycles', Event count (approx.): 9385924074 Overhead Samples Command Shared Object Symbol 66.28% 5415 cc1plus cc1plus [.] lookup_anon_field 10.04% 824 cc1plus cc1plus [.] get_class_binding_direct 5.01% 411 cc1plus cc1plus [.] fields_linear_search with -Os it's still the biggest hitter at nearly 15% compile time.