From patchwork Fri Aug 27 15:24:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 44799 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1CD38385743A for ; Fri, 27 Aug 2021 15:25:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CD38385743A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1630077918; bh=ClSk2ISa3oVrdLvI5X/Nb7flVApwhnKDnxSr9cTU9FU=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=CNqYqC9tgfntv3WDWk4/7WKETKMBiFiT2P/EaF6gixem+a6Nl/qK79S07ZrsF6CzR seWy0TEZzq+xkL4kTlIof8QEBC/0aaLdkugOK8JNilu0Ctc5LB3l9DjZJBHty03QWm rG/zw+sxN0P//es/AbaUG8a9dUADLHaks+AalNFc= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by sourceware.org (Postfix) with ESMTPS id A62F6385783E for ; Fri, 27 Aug 2021 15:25:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A62F6385783E Received: by mail-qt1-x84a.google.com with SMTP id b24-20020ac86798000000b0029eaa8c35d6so904928qtp.1 for ; Fri, 27 Aug 2021 08:25:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=ClSk2ISa3oVrdLvI5X/Nb7flVApwhnKDnxSr9cTU9FU=; b=sKGxsSsnwnx9QWoDOdt2sXqNr8/22e80b9ijvXm2fe4ih6OD/6xkK1kXKM90ycw/vE ctXW/97BTJQ6Na7AG0rS/jxgNaC6XNUxh1+TO2Y5f7Hd6WCxVF5AVSsVJRrxIQH6zHRh NC/y8ALnXy4ju3wJC+iNl0KjZFPhAPpcuIx2HEox2p8SAv52QfeQSynEBuQHdKKRiWH/ O7/zsJ4vHNLBl2Vt+o264G8fdI131eg5y8FmnAE2tHqCFPek1eZWm8n7HOPcApOJM9dJ XegvPAw6SeyPFPBF4UQv2fILcJfWiiT3NbTzZrVN2hQiZbASKb5rdzukA9grtHI9Qlnd UZDg== X-Gm-Message-State: AOAM530ZCLYcVi0LIQFSIJQkoWLRreMEsLExa5CtNIl3Wz/zMfFjsejS 00Tebs19G1LlKmOveP57lQfnkVM4Z5y3ZhaiWLo6o/R9HD080W1hwJzGYoDbj3jPxc5wPwfOu8A V4TK9JO1trw3QxdmcdON2kalMj4ZXqOFpiYMYJkC18TdYY6DPH/mj/5wyRhX+FZ+U5yHGAGM= X-Google-Smtp-Source: ABdhPJz87aS5ksOXdvEoO2F9Qoqd3PvAGWCEiz0DSALOMw6iTvxQx/cVWSor5z1vPXmRip+NESzW9u5mZXk9MA== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:210:3c20:7cb5:7c1f:3951]) (user=gprocida job=sendgmr) by 2002:a05:6214:238a:: with SMTP id fw10mr10394365qvb.27.1630077905173; Fri, 27 Aug 2021 08:25:05 -0700 (PDT) Date: Fri, 27 Aug 2021 16:24:39 +0100 Message-Id: <20210827152439.918695-1-gprocida@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog Subject: [PATCH] abg-writer: faster referenced type emission tests To: libabigail@sourceware.org X-Spam-Status: No, score=-22.1 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" When determining whether a referenced type should be emitted, various tests are done: - has the type been emitted already? hash table lookup - does the translation unit match? string comparison - is this the last translation unit? read bool variable The translation unit tests were added in recent commits and followed the hash table lookups. This resulted in a performance regression affecting Android continuous integration tests. The lookups require a hash calculation and an equality check if the hash is present. The equality checks are expensive deep equalities rather than pointer comparisons. This change reorders the tests so that the lookups happen last. This speeds up abidw by more than a factor of 10 for one Android library. * src/abg-writer.cc (write_translation_unit): Reorder referenced type emission tests for efficiency. Consolidate related comments. Signed-off-by: Giuliano Procida Reviewed-by: Matthias Maennich Signed-off-by: Giuliano Procida Reviewed-by: Matthias Maennich Signed-off-by: Dodji Seketeli --- src/abg-writer.cc | 74 ++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 46 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index bf460eed..bf0ba9e4 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -2347,49 +2347,38 @@ write_translation_unit(write_context& ctxt, // So this map of type -> string is to contain the referenced types // we need to emit. type_ptr_set_type referenced_types_to_emit; + + // For each referenced type, ensure that it is either emitted in the + // translation unit to which it belongs or in the last translation + // unit as a last resort. for (type_ptr_set_type::const_iterator i = ctxt.get_referenced_types().begin(); i != ctxt.get_referenced_types().end(); ++i) - { - if (!ctxt.type_is_emitted(*i) - && !ctxt.decl_only_type_is_emitted(*i) - // Ensure that the referenced type is emitted in the - // translation that it belongs to. - && (is_last - || ((*i)->get_translation_unit()->get_absolute_path() - == tu.get_absolute_path()))) - referenced_types_to_emit.insert(*i); - } + if ((is_last || (*i)->get_translation_unit()->get_absolute_path() + == tu.get_absolute_path()) + && !ctxt.type_is_emitted(*i) + && !ctxt.decl_only_type_is_emitted(*i)) + referenced_types_to_emit.insert(*i); for (fn_type_ptr_set_type::const_iterator i = ctxt.get_referenced_function_types().begin(); i != ctxt.get_referenced_function_types().end(); ++i) - if (!ctxt.type_is_emitted(*i) - && !ctxt.decl_only_type_is_emitted(*i) - // Ensure that the referenced type is emitted in the - // translation that it belongs to. - && (is_last - || ((*i)->get_translation_unit()->get_absolute_path() - == tu.get_absolute_path()))) - // A referenced type that was not emitted at all must be - // emitted now. + if ((is_last || (*i)->get_translation_unit()->get_absolute_path() + == tu.get_absolute_path()) + && !ctxt.type_is_emitted(*i) + && !ctxt.decl_only_type_is_emitted(*i)) referenced_types_to_emit.insert(*i); for (type_ptr_set_type::const_iterator i = ctxt.get_referenced_non_canonical_types().begin(); i != ctxt.get_referenced_non_canonical_types().end(); ++i) - if (!ctxt.type_is_emitted(*i) - && !ctxt.decl_only_type_is_emitted(*i) - // Ensure that the referenced type is emitted in the - // translation that it belongs to. - && (is_last - || ((*i)->get_translation_unit()->get_absolute_path() - == tu.get_absolute_path()))) - // A referenced type that was not emitted at all must be - // emitted now. + if ((is_last || (*i)->get_translation_unit()->get_absolute_path() + == tu.get_absolute_path()) + && !ctxt.type_is_emitted(*i) + && !ctxt.decl_only_type_is_emitted(*i)) referenced_types_to_emit.insert(*i); // Ok, now let's emit the referenced type for good. @@ -2438,34 +2427,27 @@ write_translation_unit(write_context& ctxt, // there are still some referenced types in there that are not // emitted yet. If yes, then we'll emit those again. + // For each referenced type, ensure that it is either emitted in + // the translation unit to which it belongs or in the last + // translation unit as a last resort. for (type_ptr_set_type::const_iterator i = ctxt.get_referenced_types().begin(); i != ctxt.get_referenced_types().end(); ++i) - if (!ctxt.type_is_emitted(*i) - && !ctxt.decl_only_type_is_emitted(*i) - // Ensure that the referenced type is emitted in the - // translation that it belongs to. - && (is_last - || ((*i)->get_translation_unit()->get_absolute_path() - == tu.get_absolute_path()))) - // A referenced type that was not emitted at all must be - // emitted now. + if ((is_last || (*i)->get_translation_unit()->get_absolute_path() + == tu.get_absolute_path()) + && !ctxt.type_is_emitted(*i) + && !ctxt.decl_only_type_is_emitted(*i)) referenced_types_to_emit.insert(*i); for (type_ptr_set_type::const_iterator i = ctxt.get_referenced_non_canonical_types().begin(); i != ctxt.get_referenced_non_canonical_types().end(); ++i) - if (!ctxt.type_is_emitted(*i) - && !ctxt.decl_only_type_is_emitted(*i) - // Ensure that the referenced type is emitted in the - // translation that it belongs to. - && (is_last - || ((*i)->get_translation_unit()->get_absolute_path() - == tu.get_absolute_path()))) - // A referenced type that was not emitted at all must be - // emitted now. + if ((is_last || (*i)->get_translation_unit()->get_absolute_path() + == tu.get_absolute_path()) + && !ctxt.type_is_emitted(*i) + && !ctxt.decl_only_type_is_emitted(*i)) referenced_types_to_emit.insert(*i); }