From patchwork Tue Aug 17 07:14:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 12440563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36005C4338F for ; Tue, 17 Aug 2021 07:14:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1565C60F5E for ; Tue, 17 Aug 2021 07:14:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238112AbhHQHP0 (ORCPT ); Tue, 17 Aug 2021 03:15:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233996AbhHQHPZ (ORCPT ); Tue, 17 Aug 2021 03:15:25 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8BE5C0613C1 for ; Tue, 17 Aug 2021 00:14:52 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id q11-20020a7bce8b0000b02902e6880d0accso1168231wmj.0 for ; Tue, 17 Aug 2021 00:14:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=iX2L3ncslySytNVuPS1S0N4xVePIhQxVLRAfBjepfl4=; b=Nzy7t744HlRlak4XPUeNvtFwA+0Wpc7+KO36inImlH881wx1YMa/PxccFPr7Wi3WKY Hv/Tsh8pS6WmZKJvX/BeK3Bf5RxQrkwKKlS2sSm+Pcg89Tp5R3bGFcBBbM8TfhkgEGU/ u2J8ijqDqEZME9oISoeBylDWJaX4vSzBAxtLmrHJQDjyuBViHGS69huV4ed4r+YT9so0 hJxvd3cCyBoIl+nzzuYHh2CwnkI0NqP/G4IMZvw7uPSVPLdryQeH1VCkzyF9ayskdw2P sXzDitt9amIPSzo7wr1mmKmqzHbiX4yrQ+nB0Zq0gYS4ioeeASdPLwGIU5JsFzz9U64k e4/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=iX2L3ncslySytNVuPS1S0N4xVePIhQxVLRAfBjepfl4=; b=IqK+VENKz27GjM6aDPA+rOlkMliP8yd2C9TZovdS/rzX8iX+lV4IYacw5jAXPSqjDN lHVYCvU5JkP3+Pt4CRBuyqaLHKdyYOt51yu7lUpLiCKG8DgciDqDtnHLWiIi6EtE3+Nb N1wuUG069wY2kp8e5sGEpbX0b7y21JjJ1wndMJZtoX2apauR8EjLimYYvWleDvk4WyG0 OzlF3LzAqdpeJ6mbV9SsXgJ6/QMFIWIhKi8/IC0oYBUl0zqQFIxpgiedPOh82+lYHUSK 52VVsTu5kw+rSfkwj/lOD4MqjSp2DJmjyKgjxIRShM4LPDjgNoS4I0M0zLJIt1sEg93c wYJw== X-Gm-Message-State: AOAM532/yF0Oit/yfc9eac+Kqa5PJbsuI3xBmE9uTt3F1QUhMy6u3WCn nwT5n96HqskUkCEWTpGWmfV9QxsqIB0= X-Google-Smtp-Source: ABdhPJw8UB2MLJbrhXXRk/pXSRz+/5oDi2kRhQieUUTiCrB6ErnNnWDL5/UNFT9S45duxGxgXO9j1w== X-Received: by 2002:a05:600c:210a:: with SMTP id u10mr1863272wml.162.1629184491248; Tue, 17 Aug 2021 00:14:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r12sm1352212wrv.96.2021.08.17.00.14.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 00:14:50 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 17 Aug 2021 07:14:45 +0000 Subject: [PATCH 1/5] [GSOC] ref-filter: skip parse_object_buffer in some cases Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Christian Couder , Hariom Verma , Bagas Sanjaya , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Eric Sunshine , Philip Oakley , ZheNing Hu , ZheNing Hu Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: ZheNing Hu From: ZheNing Hu When we are using some atoms such as %(raw), %(objectname), %(objecttype), we don't need to parse the content of the object, so we can skip parse_object_buffer() for performance optimization. It is worth noting that in these cases, we still need to call parse_object_buffer() for parsing: 1. The atom type is one of %(tag), %(type), %(object), %(tree), %(numparent) or %(parent). 2. The type of the object is tag and the atom need to be dereferenced e.g. %(*objecttype). Mentored-by: Christian Couder Mentored-by: Hariom Verma Signed-off-by: ZheNing Hu --- ref-filter.c | 49 +++++++++++++++++++++++++++++++++++++------------ ref-filter.h | 5 +++-- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 93ce2a6ef2e..65ba00633dc 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1009,6 +1009,20 @@ static int reject_atom(enum atom_type atom_type) return atom_type == ATOM_REST; } +static int need_parse_buffer(enum atom_type atom_type) { + switch (atom_type) { + case ATOM_TAG: + case ATOM_TYPE: + case ATOM_OBJECT: + case ATOM_TREE: + case ATOM_NUMPARENT: + case ATOM_PARENT: + return 1; + default: + return 0; + } +} + /* * Make sure the format string is well formed, and parse out * the used atoms. @@ -1029,6 +1043,8 @@ int verify_ref_format(struct ref_format *format) at = parse_ref_filter_atom(format, sp + 2, ep, &err); if (at < 0) die("%s", err.buf); + if (need_parse_buffer(used_atom[at].atom_type)) + format->can_skip_parse_buffer = 0; if (reject_atom(used_atom[at].atom_type)) die(_("this command reject atom %%(%.*s)"), (int)(ep - sp - 2), sp + 2); @@ -1524,14 +1540,16 @@ static void grab_values(struct atom_value *val, int deref, struct object *obj, s { void *buf = data->content; - switch (obj->type) { + switch (data->type) { case OBJ_TAG: - grab_tag_values(val, deref, obj); + if (obj) + grab_tag_values(val, deref, obj); grab_sub_body_contents(val, deref, data); grab_person("tagger", val, deref, buf); break; case OBJ_COMMIT: - grab_commit_values(val, deref, obj); + if (obj) + grab_commit_values(val, deref, obj); grab_sub_body_contents(val, deref, data); grab_person("author", val, deref, buf); grab_person("committer", val, deref, buf); @@ -1757,14 +1775,21 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj BUG("Object size is less than zero."); if (oi->info.contentp) { - *obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten); - if (!*obj) { - if (!eaten) - free(oi->content); - return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"), - oid_to_hex(&oi->oid), ref->refname); + if (ref->can_skip_parse_buffer && + ((!deref && + (!need_tagged || oi->type != OBJ_TAG)) || + deref)) { + grab_values(ref->value, deref, NULL, oi); + } else { + *obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten); + if (!*obj) { + if (!eaten) + free(oi->content); + return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"), + oid_to_hex(&oi->oid), ref->refname); + } + grab_values(ref->value, deref, *obj, oi); } - grab_values(ref->value, deref, *obj, oi); } grab_common_values(ref->value, deref, oi); @@ -1988,7 +2013,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) * If there is no atom that wants to know about tagged * object, we are done. */ - if (!need_tagged || (obj->type != OBJ_TAG)) + if (!need_tagged || (oi.type != OBJ_TAG)) return 0; /* @@ -2595,7 +2620,7 @@ int format_ref_array_item(struct ref_array_item *info, state.quote_style = format->quote_style; push_stack_element(&state.stack); - + info->can_skip_parse_buffer = format->can_skip_parse_buffer; for (cp = format->format; *cp && (sp = find_next(cp)); cp = ep + 1) { struct atom_value *atomv; int pos; diff --git a/ref-filter.h b/ref-filter.h index c15dee8d6b9..5bceae1dac9 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -40,6 +40,7 @@ struct ref_array_item { struct object_id objectname; const char *rest; int flag; + int can_skip_parse_buffer; unsigned int kind; const char *symref; struct commit *commit; @@ -81,12 +82,12 @@ struct ref_format { int quote_style; int use_rest; int use_color; - + int can_skip_parse_buffer; /* Internal state to ref-filter */ int need_color_reset_at_eol; }; -#define REF_FORMAT_INIT { .use_color = -1 } +#define REF_FORMAT_INIT { .use_color = -1, .can_skip_parse_buffer = 1 } /* Macros for checking --merged and --no-merged options */ #define _OPT_MERGED_NO_MERGED(option, filter, h) \ From patchwork Tue Aug 17 07:14:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 12440565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD1CEC4320E for ; Tue, 17 Aug 2021 07:14:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D211600D3 for ; Tue, 17 Aug 2021 07:14:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234595AbhHQHP3 (ORCPT ); Tue, 17 Aug 2021 03:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234275AbhHQHP0 (ORCPT ); Tue, 17 Aug 2021 03:15:26 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68544C0613CF for ; Tue, 17 Aug 2021 00:14:53 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id r6so27111870wrt.4 for ; Tue, 17 Aug 2021 00:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=woILMgSiLm64c3txo/J9qWJxAkBA+I43w0V+oZzWMng=; b=iIvE9YUVCUmXBfzQRbheWcbMQXL1cs8WE0YIdpHneTazDCkFqZj3GCkK01W0PPQqom CE1aMjgsOxS11OGHbuMiYuzXGCEuaOtLMEsxtxzJy18fffP6Uy5Cd+3l1ECer+Ii+FwT J0RRJTm7PVHTMJ+nsy5f3N2mCv0LQG9iuvK33cjKi8Efv1PHHQbvS/jOGaOV2a7DKYTD jD5L7dyYg7FNCw5xYUFDpbBKIfVCEToveWAYjS+ewG/oi1xIz7U4mYrpoZj7WgxO+e2x AyNK596gJNQtdfeogJvEoht9v/ERBrXwrmMRH9lEaJKn7supPUdJCgwJIus/LuqVMtTD 7QCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=woILMgSiLm64c3txo/J9qWJxAkBA+I43w0V+oZzWMng=; b=C4mYgokVyvQJwSGWZGlEL7pSttylBqdGWq/plPFR6zIPzsJtXoCO+PZYL1RE4DdC9a tENa3qEWO2HRctU2voUDAMK7fD4beJ78NbGM8ecf2J9+oMrM4SZXBX4TM7GkHBGymXzh twvGBV/uOB1FIAl3/Ab8kVWffqdhVqcjY7Qpu2EUr4WgKzPPi1UMe4LeqTTPg6qOPmG6 S6yKldsehgCoSBnxmEmG9B9Atl6xyPzWH5J4XsuOBRZUB96Kwbbw5qXcG//kgb6NVBci A2Tc53fvUcfOQD4/SSl3hJiKtpNcRuj0HnZjnp/nsKp9FGcRtY5XhvyPNVZGEXgeK01l UAnQ== X-Gm-Message-State: AOAM533qSqRA4swgXZc4S8YUjw/vmEIYf/WAI/VmoyrMmFWpTGQEfkqL xjXBlBUNtbtICo1AFWVYFC4SRGhQI+o= X-Google-Smtp-Source: ABdhPJwBH1wW6ulsuloM82xmE9bedPRaqwfpzNdXd95JsfTTWwomRyWWNiGGyP07bqnL0Wruywzr5Q== X-Received: by 2002:a5d:4e0d:: with SMTP id p13mr2171470wrt.274.1629184491842; Tue, 17 Aug 2021 00:14:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a9sm1342555wrv.37.2021.08.17.00.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 00:14:51 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 17 Aug 2021 07:14:46 +0000 Subject: [PATCH 2/5] [GSOC] ref-filter: remove second parsing in format_ref_array_item Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Christian Couder , Hariom Verma , Bagas Sanjaya , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Eric Sunshine , Philip Oakley , ZheNing Hu , ZheNing Hu Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: ZheNing Hu From: ZheNing Hu We parsed format string in verify_ref_format() and stored the parsed atom in used_atom array. But in format_ref_array_item() we have another round of parsing format string. This affects performance. Introducing the struct parsed_atom_list which can save the current atom's start and end address in format string and its index in used_atom. All parsed_atom_list entry are linked together in the form of linked list, and the head node of the linked list is stored in struct ref_format. Create clear_parsed_atom_list() which can used to clear the nodes on the linked list. This can bring performance improvement. Mentored-by: Christian Couder Mentored-by: Hariom Verma Signed-off-by: ZheNing Hu --- builtin/branch.c | 2 ++ builtin/for-each-ref.c | 3 ++- builtin/tag.c | 2 ++ builtin/verify-tag.c | 2 ++ ref-filter.c | 45 +++++++++++++++++++++++++++++++++--------- ref-filter.h | 11 +++++++++++ 6 files changed, 55 insertions(+), 10 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index b23b1d1752a..e361f8cc661 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -459,6 +459,7 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin strbuf_release(&err); strbuf_release(&out); ref_array_clear(&array); + clear_parsed_atom_list(&format->parsed_atom_head); free(to_free); } @@ -678,6 +679,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) memset(&filter, 0, sizeof(filter)); filter.kind = FILTER_REFS_BRANCHES; filter.abbrev = -1; + INIT_LIST_HEAD(&format.parsed_atom_head); if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(builtin_branch_usage, options); diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 89cb6307d46..6e22d80d5b5 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -53,8 +53,8 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) memset(&array, 0, sizeof(array)); memset(&filter, 0, sizeof(filter)); - format.format = "%(objectname) %(objecttype)\t%(refname)"; + INIT_LIST_HEAD(&format.parsed_atom_head); git_config(git_default_config, NULL); @@ -96,6 +96,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) ref_array_clear(&array); free_commit_list(filter.with_commit); free_commit_list(filter.no_commit); + clear_parsed_atom_list(&format.parsed_atom_head); UNLEAK(sorting); return 0; } diff --git a/builtin/tag.c b/builtin/tag.c index 452558ec957..549339cbbe4 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -78,6 +78,7 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, strbuf_release(&output); ref_array_clear(&array); free(to_free); + clear_parsed_atom_list(&format->parsed_atom_head); return 0; } @@ -493,6 +494,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) memset(&filter, 0, sizeof(filter)); filter.lines = -1; opt.sign = -1; + INIT_LIST_HEAD(&format.parsed_atom_head); argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0); diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c index f45136a06ba..8b0a2b2587c 100644 --- a/builtin/verify-tag.c +++ b/builtin/verify-tag.c @@ -39,6 +39,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix) OPT_END() }; + INIT_LIST_HEAD(&format.parsed_atom_head); git_config(git_verify_tag_config, NULL); argc = parse_options(argc, argv, prefix, verify_tag_options, @@ -73,5 +74,6 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix) if (format.format) pretty_print_ref(name, &oid, &format); } + clear_parsed_atom_list(&format.parsed_atom_head); return had_error; } diff --git a/ref-filter.c b/ref-filter.c index 65ba00633dc..76a31fb79b1 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1035,6 +1035,7 @@ int verify_ref_format(struct ref_format *format) for (cp = format->format; *cp && (sp = find_next(cp)); ) { struct strbuf err = STRBUF_INIT; const char *color, *ep = strchr(sp, ')'); + struct parsed_atom_list *e; int at; if (!ep) @@ -1043,6 +1044,12 @@ int verify_ref_format(struct ref_format *format) at = parse_ref_filter_atom(format, sp + 2, ep, &err); if (at < 0) die("%s", err.buf); + e = xmalloc(sizeof(*e)); + e->beg = sp + 2; + e->end = ep; + e->at = at; + list_add_tail(&e->list, &format->parsed_atom_head); + if (need_parse_buffer(used_atom[at].atom_type)) format->can_skip_parse_buffer = 0; if (reject_atom(used_atom[at].atom_type)) @@ -2615,25 +2622,31 @@ int format_ref_array_item(struct ref_array_item *info, struct strbuf *final_buf, struct strbuf *error_buf) { - const char *cp, *sp, *ep; + const char *cp, *sp; + struct list_head *item; struct ref_formatting_state state = REF_FORMATTING_STATE_INIT; state.quote_style = format->quote_style; push_stack_element(&state.stack); info->can_skip_parse_buffer = format->can_skip_parse_buffer; - for (cp = format->format; *cp && (sp = find_next(cp)); cp = ep + 1) { + + cp = format->format; + + list_for_each(item, &format->parsed_atom_head) { struct atom_value *atomv; - int pos; + struct parsed_atom_list *e = + list_entry(item, struct parsed_atom_list, list); - ep = strchr(sp, ')'); - if (cp < sp) - append_literal(cp, sp, &state); - pos = parse_ref_filter_atom(format, sp + 2, ep, error_buf); - if (pos < 0 || get_ref_atom_value(info, pos, &atomv, error_buf) || + if (cp < e->beg - 2) + append_literal(cp, e->beg - 2, &state); + if (get_ref_atom_value(info, e->at, &atomv, error_buf) || atomv->handler(atomv, &state, error_buf)) { pop_stack_element(&state.stack); return -1; } + cp = e->end + 1; + if (!*cp) + break; } if (*cp) { sp = cp + strlen(cp); @@ -2681,10 +2694,12 @@ static int parse_sorting_atom(const char *atom) * This parses an atom using a dummy ref_format, since we don't * actually care about the formatting details. */ + int res; struct ref_format dummy = REF_FORMAT_INIT; const char *end = atom + strlen(atom); struct strbuf err = STRBUF_INIT; - int res = parse_ref_filter_atom(&dummy, atom, end, &err); + + res = parse_ref_filter_atom(&dummy, atom, end, &err); if (res < 0) die("%s", err.buf); strbuf_release(&err); @@ -2757,3 +2772,15 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) return 0; } + +void clear_parsed_atom_list(struct list_head *parsed_atom_head) +{ + struct list_head *pos, *tmp; + struct parsed_atom_list *item; + + list_for_each_safe(pos, tmp, parsed_atom_head) { + item = list_entry(pos, struct parsed_atom_list, list); + list_del(pos); + free(item); + } +} diff --git a/ref-filter.h b/ref-filter.h index 5bceae1dac9..df54836a643 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -72,6 +72,13 @@ struct ref_filter { verbose; }; +struct parsed_atom_list { + const char *beg; + const char *end; + int at; + struct list_head list; +}; + struct ref_format { /* * Set these to define the format; make sure you call @@ -85,6 +92,7 @@ struct ref_format { int can_skip_parse_buffer; /* Internal state to ref-filter */ int need_color_reset_at_eol; + struct list_head parsed_atom_head; }; #define REF_FORMAT_INIT { .use_color = -1, .can_skip_parse_buffer = 1 } @@ -112,6 +120,9 @@ struct ref_format { int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int type); /* Clear all memory allocated to ref_array */ void ref_array_clear(struct ref_array *array); +/* Clear the parsed_atom_list in ref_format*/ +void clear_parsed_atom_list(struct list_head *parsed_atom_head); + /* Used to verify if the given format is correct and to parse out the used atoms */ int verify_ref_format(struct ref_format *format); /* Sort the given ref_array as per the ref_sorting provided */ From patchwork Tue Aug 17 07:14:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 12440567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B9F2C4338F for ; Tue, 17 Aug 2021 07:14:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1FC3060F5E for ; Tue, 17 Aug 2021 07:14:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238291AbhHQHPa (ORCPT ); Tue, 17 Aug 2021 03:15:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238067AbhHQHP0 (ORCPT ); Tue, 17 Aug 2021 03:15:26 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD234C061764 for ; Tue, 17 Aug 2021 00:14:53 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id q10so27112494wro.2 for ; Tue, 17 Aug 2021 00:14:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=c+lkod6TvlzaEEpGl/bzbZCP/LPjMFQTQhy6j7hTJQ0=; b=eTvhvtF1ZVFmDVQoOLQBw0IzSAwsW1tQj3MDBCmq09sCa2tQNvKqYVp823F8OzXWZt hsENRDtZqXGKw1s/0qz/43HJX/IdAXXd5RgeWhh5O/lS+TCkyKV2zq0O4wCM14euia/n 6Lk/xnBnPHM1a+DDn97QZlqfxBNJCI2UZefmCnagSH0kIJvwtVtkVRUo0DzbsSdXz7rF 6DGlsKWCkZVh9t1Vgiqy/7Ic0RziOfaKIsXdq59mxIgNVed2LpCvTr29EGzAAUng16sV gjL3t9BwOenl+e3mzA2o/mT/aZ7C7UxUOXflvswGzkvL7wkcwyC2TyKU3yzo0Rl0XfJy JqHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=c+lkod6TvlzaEEpGl/bzbZCP/LPjMFQTQhy6j7hTJQ0=; b=M5s1C6KEqHZKojkGQzSjeknwFFGaP0YrpCWCQCIdLVBJMv/tCEoavR/4FtpswTqqm/ LeJOifjkIOV80QhB1FwKWOGmClMEQoV6z2Gdy18GLmn4VIvNqJuco01Pxuogh30iUxMx hbo59quCghSFqf58SXD2gWaUY70xifRAFC/Ip1n3QdFTtkq1aiFiMrXkHGkgAEkCHyBr EDT9k6zzmq25E2pQQmN1IxzGILCIswWkPOmAMBJHkAdbEreHXlk8sYh/NAxRjD2iWD+o 3VOkH6z76LWaJGQRkAQaMnYl6v6U6558Q9qQRHJTdduA2t1YzVD5tqHtpnonDiiD/iap II/A== X-Gm-Message-State: AOAM5337aBx86yL2fQhKy8xdL7gGggtLR3IVA9N+YRygvo6so2PIS9NA kMVmNmoM94H+CkmyDYC6PE9qeAdBlrU= X-Google-Smtp-Source: ABdhPJyA8FdMIFNbvFa5CWIJx4XutfWDtbJ3URu1E4kYfkqBdNkwOKIw24k5Ier1OBu+fX3ZUtSqcg== X-Received: by 2002:a5d:6912:: with SMTP id t18mr2167618wru.359.1629184492548; Tue, 17 Aug 2021 00:14:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a3sm1320811wrx.38.2021.08.17.00.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 00:14:52 -0700 (PDT) Message-Id: <3760ff032bb1dec3812881fd408f8d78ec125477.1629184489.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 17 Aug 2021 07:14:47 +0000 Subject: [PATCH 3/5] [GSOC] ref-filter: reuse final buffer Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Christian Couder , Hariom Verma , Bagas Sanjaya , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Eric Sunshine , Philip Oakley , ZheNing Hu , ZheNing Hu Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: ZheNing Hu From: ZheNing Hu In format_ref_array_item(), we add the object data to ref_formatting_state, and copy the data from ref_formatting_state to final_buf at the end. There are huge copies of data. Because final_buf will be cleared before every time we call format_ref_array_item(). So we actually add content to an empty strbuf. We can add the object's data directly to this final_buffer instead of adding objects' data to state.stack->output first, then copy to final_buf. Add a can_reuse_final_buffer flag to struct ref_format and create can_reuse_final_buffer() to check if we are use %(align), %(end), %(if), %(then), %(else). If not, we can reuse the buf of finnal_buf. Reuse the buffer address of final_buf in format_ref_array_item(), we directly add the data to the final buffer, return the content to final_buf at the end. This will bring performance improvements. Mentored-by: Christian Couder Mentored-by: Hariom Verma Signed-off-by: ZheNing Hu --- ref-filter.c | 39 ++++++++++++++++++++++++++++++++++----- ref-filter.h | 3 ++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 76a31fb79b1..7106d4c1c4c 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1023,6 +1023,19 @@ static int need_parse_buffer(enum atom_type atom_type) { } } +static int can_reuse_final_buffer(enum atom_type atom_type) { + switch (atom_type) { + case ATOM_ALIGN: + case ATOM_END: + case ATOM_IF: + case ATOM_THEN: + case ATOM_ELSE: + return 0; + default: + return 1; + } +} + /* * Make sure the format string is well formed, and parse out * the used atoms. @@ -1054,6 +1067,7 @@ int verify_ref_format(struct ref_format *format) format->can_skip_parse_buffer = 0; if (reject_atom(used_atom[at].atom_type)) die(_("this command reject atom %%(%.*s)"), (int)(ep - sp - 2), sp + 2); + format->can_reuse_final_buffer = can_reuse_final_buffer(used_atom[at].atom_type); if ((format->quote_style == QUOTE_PYTHON || format->quote_style == QUOTE_SHELL || @@ -2627,7 +2641,14 @@ int format_ref_array_item(struct ref_array_item *info, struct ref_formatting_state state = REF_FORMATTING_STATE_INIT; state.quote_style = format->quote_style; - push_stack_element(&state.stack); + if (format->can_reuse_final_buffer) { + struct ref_formatting_stack *s = xmalloc(sizeof(struct ref_formatting_stack)); + s->output = *final_buf; + s->prev = state.stack; + state.stack = s; + } else { + push_stack_element(&state.stack); + } info->can_skip_parse_buffer = format->can_skip_parse_buffer; cp = format->format; @@ -2641,7 +2662,8 @@ int format_ref_array_item(struct ref_array_item *info, append_literal(cp, e->beg - 2, &state); if (get_ref_atom_value(info, e->at, &atomv, error_buf) || atomv->handler(atomv, &state, error_buf)) { - pop_stack_element(&state.stack); + if (!format->can_reuse_final_buffer) + pop_stack_element(&state.stack); return -1; } cp = e->end + 1; @@ -2656,16 +2678,23 @@ int format_ref_array_item(struct ref_array_item *info, struct atom_value resetv = ATOM_VALUE_INIT; resetv.s = GIT_COLOR_RESET; if (append_atom(&resetv, &state, error_buf)) { - pop_stack_element(&state.stack); + if (!format->can_reuse_final_buffer) + pop_stack_element(&state.stack); return -1; } } if (state.stack->prev) { + assert(!format->can_reuse_final_buffer); pop_stack_element(&state.stack); return strbuf_addf_ret(error_buf, -1, _("format: %%(end) atom missing")); } - strbuf_addbuf(final_buf, &state.stack->output); - pop_stack_element(&state.stack); + if(format->can_reuse_final_buffer) { + *final_buf = state.stack->output; + free(state.stack); + } else { + strbuf_addbuf(final_buf, &state.stack->output); + pop_stack_element(&state.stack); + } return 0; } diff --git a/ref-filter.h b/ref-filter.h index df54836a643..a62a14a2e43 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -92,10 +92,11 @@ struct ref_format { int can_skip_parse_buffer; /* Internal state to ref-filter */ int need_color_reset_at_eol; + int can_reuse_final_buffer; struct list_head parsed_atom_head; }; -#define REF_FORMAT_INIT { .use_color = -1, .can_skip_parse_buffer = 1 } +#define REF_FORMAT_INIT { .use_color = -1, .can_skip_parse_buffer = 1, .can_reuse_final_buffer = 1 } /* Macros for checking --merged and --no-merged options */ #define _OPT_MERGED_NO_MERGED(option, filter, h) \ From patchwork Tue Aug 17 07:14:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 12440569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F341BC4320A for ; Tue, 17 Aug 2021 07:14:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7D0460F5E for ; Tue, 17 Aug 2021 07:14:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238446AbhHQHPb (ORCPT ); Tue, 17 Aug 2021 03:15:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233688AbhHQHP1 (ORCPT ); Tue, 17 Aug 2021 03:15:27 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B4E8C061764 for ; Tue, 17 Aug 2021 00:14:54 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id r7so27177849wrs.0 for ; Tue, 17 Aug 2021 00:14:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=hH5AYoT2omWwWQpGeFarOuPdMIQukXOrhc+KpYnmrJA=; b=RtYZA7X1mfBJFt5gz8TEE1hcR0ijiesHSvIakZvOG5VeUy3D13taYpwFtJW67I5Hy2 MdSW+QQUOWkNZ158utGgTSmXgaFI8/RR6kBQ7r5uhRCgA39gp2d3PC+G2WHDWAl+nMvw GosVboI2JuWJqnaCBD8HK94ibAbDcEmFPA9z/4gsSUJMVV2AbR34IjDWOLWSxjQLODuH iOiKpbhN3SboEys3sUXauAE/wLl/dnV2dEA0MZBjfphaoX3y4Ax3FyUIWt8zGOzQHZ0A 3GzsskHbmICOyCMttUN2pbVb6OVwWpWk/exlG/Zyq0LYOAscmVELp19VXm3FpnEv/fcV appg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=hH5AYoT2omWwWQpGeFarOuPdMIQukXOrhc+KpYnmrJA=; b=ggU7BtoquinGP9Wyd0QjJqr5trRcn/Onn/VQKPforhyTHr7IenfgHLcel8Ycco4eR2 ps3Ymh4bcmuPjv7s+qvF1JeIb0+2gHh874nRi75Z1+QWEK4OfGdPbPiks5VxbWeLXbPF McghNWqnKOO8qeVQgA8AFBBZPcDyPdbhThpFv+EiqYbFyDQlCEq/whgQSKfRUx5p8hhF +Kpv95FHZ3qn3ePvbB0FvdMWfVD8Jb6PVezoqWidUaZqVWVf3aTY9R8PnfTPQu9JYSvT C+h2gMBkTvi+v5uEK7b6ejogxNazr5AKpOWTBdqc8slLpIGsB+kZBfblltgCOwfITMl7 ovlA== X-Gm-Message-State: AOAM530ZS7SUaNbyKOpzSTGDk8MPi1YBdOYzxQphs5VswTEKfYH83BmH 5WQH8odpmJnI8c94Zyev9B8uQmoQSSU= X-Google-Smtp-Source: ABdhPJzs8ou1nUn/Xtfc198lApnB2AgsvQK7tpx8Vg7s0yYI2HmKygw5GzS9e49kOeDHEdh5B1V52g== X-Received: by 2002:adf:f3ca:: with SMTP id g10mr450630wrp.379.1629184493091; Tue, 17 Aug 2021 00:14:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x13sm1313410wrq.44.2021.08.17.00.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 00:14:52 -0700 (PDT) Message-Id: <3899fbe498f629d1af7dcea792b14eccdbb51af5.1629184489.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 17 Aug 2021 07:14:48 +0000 Subject: [PATCH 4/5] [GSOC] ref-filter: reduce unnecessary object_info comparisons Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Christian Couder , Hariom Verma , Bagas Sanjaya , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Eric Sunshine , Philip Oakley , ZheNing Hu , ZheNing Hu Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: ZheNing Hu From: ZheNing Hu In populate_value() we use an empty struct object_info compare with oi and oi_deref, which determine if we can return early, this is actually very inefficient. So add a need_get_object_info flag in global variables, which used to indicate whether we need call get_object() or we can return early. So we only need to compare only one byte instead of comparing the entire huge object_info struct. Mentored-by: Christian Couder Mentored-by: Hariom Verma Signed-off-by: ZheNing Hu --- ref-filter.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 7106d4c1c4c..35e221e7ec8 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -212,7 +212,7 @@ static struct used_atom { char *head; } u; } *used_atom; -static int used_atom_cnt, need_tagged, need_symref; +static int used_atom_cnt, need_tagged, need_symref, need_get_object_info; /* * Expand string, append it to strbuf *sb, then return error code ret. @@ -318,10 +318,13 @@ static int objecttype_atom_parser(struct ref_format *format, struct used_atom *a { if (arg) return strbuf_addf_ret(err, -1, _("%%(objecttype) does not take arguments")); - if (*atom->name == '*') + if (*atom->name == '*') { oi_deref.info.typep = &oi_deref.type; - else + need_get_object_info = 1; + } else { oi.info.typep = &oi.type; + need_get_object_info = 1; + } return 0; } @@ -330,16 +333,23 @@ static int objectsize_atom_parser(struct ref_format *format, struct used_atom *a { if (!arg) { atom->u.objectsize.option = O_SIZE; - if (*atom->name == '*') + if (*atom->name == '*') { oi_deref.info.sizep = &oi_deref.size; - else + need_get_object_info = 1; + } else { oi.info.sizep = &oi.size; + need_get_object_info = 1; + } } else if (!strcmp(arg, "disk")) { atom->u.objectsize.option = O_SIZE_DISK; - if (*atom->name == '*') + if (*atom->name == '*') { oi_deref.info.disk_sizep = &oi_deref.disk_size; - else + need_get_object_info = 1; + } + else { oi.info.disk_sizep = &oi.disk_size; + need_get_object_info = 1; + } } else return strbuf_addf_ret(err, -1, _("unrecognized %%(objectsize) argument: %s"), arg); return 0; @@ -354,6 +364,7 @@ static int deltabase_atom_parser(struct ref_format *format, struct used_atom *at oi_deref.info.delta_base_oid = &oi_deref.delta_base_oid; else oi.info.delta_base_oid = &oi.delta_base_oid; + need_get_object_info = 1; return 0; } @@ -720,6 +731,7 @@ static int parse_ref_filter_atom(struct ref_format *format, used_atom[at].type = valid_atom[i].cmp_type; used_atom[at].source = valid_atom[i].source; if (used_atom[at].source == SOURCE_OBJ) { + need_get_object_info = 1; if (*atom == '*') oi_deref.info.contentp = &oi_deref.content; else @@ -1871,7 +1883,6 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) { struct object *obj; int i; - struct object_info empty = OBJECT_INFO_INIT; CALLOC_ARRAY(ref->value, used_atom_cnt); @@ -2019,10 +2030,11 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) oid_to_hex(&ref->objectname), ref->refname); } - if (need_tagged) + if (need_tagged) { oi.info.contentp = &oi.content; - if (!memcmp(&oi.info, &empty, sizeof(empty)) && - !memcmp(&oi_deref.info, &empty, sizeof(empty))) + need_get_object_info = 1; + } + if (!need_get_object_info) return 0; From patchwork Tue Aug 17 07:14:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 12440571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A92CC432BE for ; Tue, 17 Aug 2021 07:15:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4665F60FBF for ; Tue, 17 Aug 2021 07:15:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238472AbhHQHPc (ORCPT ); Tue, 17 Aug 2021 03:15:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238230AbhHQHP2 (ORCPT ); Tue, 17 Aug 2021 03:15:28 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15876C0613C1 for ; Tue, 17 Aug 2021 00:14:55 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id w24so5280828wmi.5 for ; Tue, 17 Aug 2021 00:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Zzi6SFtaqQoN+uOiLVvAeRODXFeKD5NWEZX6kME8IyI=; b=pHYQgE6PxARnv9lUB3S5faPn5Wa8KU5/ldFbFqLULx+P1eN6QkNMjim/RU8MZvaM6L htTjhmaTHKed5wHGBEhcDV5bkJ7N7CvivbG0G8AQFozv4Dt5yEvdoFCdQYMW0hZX/eiU Gfc8dhEhzSTCrFmKH73kjQFimJwzhplok9cQ71p6REl4Kp8SXr9Pj2VkcaWEkqytTejr hyf0MXFcyWMcKgiAGXENf+EOM3n5A+o1I9GKXv4Se0zQP8Jyo3PlyLD8Pr44ikuqyehj x4g0ux8p1NnqjiureggPqys9zatJXdkJ1pm1rcn3rwx6f0j2Ba9+chykFmlHGhnX9LL0 xqIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Zzi6SFtaqQoN+uOiLVvAeRODXFeKD5NWEZX6kME8IyI=; b=azPuj4zlnFXCADT//uedcmHexKzCGDTeZHZGrijLMG0Da7xxaTUgSanfNFZVAUhk24 ZCWed1tVYblxYzwYJ3grhQqJZ+rUvld8QjsRvfE1xBzACeFePvxoEOcmcQXVlL47YBSO fRfvjZVQ7sut3xYdR6xizGwsuMnuG6slEeEHZgos+zWSAB8Jvz7o1hHlYOPzocfJeFlV zxVx/FWSAt1n7ecip1EnbbGd1oyR9hZYsO6OssiiBERSlIQD/ggzD4YI3zsdK6PAUZjE fjkeqtM5xaAS3wRnr5XZn/50Ri1nC7VPgmGJL9JlPAlpesHg6OWw0AliDuKiMLD7gsSt AxaA== X-Gm-Message-State: AOAM533SbE+U5MWvCnn793CZEK6WYPt6hJrHH6AdmlZvytGbVsp4A0ax R+oTMm0kZMjRS3yLHuUCjXpw+HYc3Zg= X-Google-Smtp-Source: ABdhPJxQ4DIwypSAfGTGShVIdZE31Ljam7Lp/1ekXjrrq7Ik7uT3d6s6I8u5fThbhQHDKstmIIpahw== X-Received: by 2002:a05:600c:2281:: with SMTP id 1mr1832830wmf.9.1629184493700; Tue, 17 Aug 2021 00:14:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r12sm1352363wrv.96.2021.08.17.00.14.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 00:14:53 -0700 (PDT) Message-Id: <3476e548338623f954abd73192360bcba7df3d89.1629184489.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 17 Aug 2021 07:14:49 +0000 Subject: [PATCH 5/5] [GSOC]: ref-filter: instead CALLOC_ARRAY to ALLOC_ARRAY Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Christian Couder , Hariom Verma , Bagas Sanjaya , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Eric Sunshine , Philip Oakley , ZheNing Hu , ZheNing Hu Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: ZheNing Hu From: ZheNing Hu populate_value() uses CALLOC_ARRAY() to allocate dynamic memory for ref->value. But after that, we immediately assign values to its members in the for loop. This shows that it is not necessary to use CALLOC_ARRAY() for ref->value to clear the memory. Therefore, use ALLOC_ARRAY() instead of CALLOC_ARRAY() to reduce the overhead caused by clearing the memory. This can bring performance optimizations. Mentored-by: Christian Couder Mentored-by: Hariom Verma Signed-off-by: ZheNing Hu --- ref-filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ref-filter.c b/ref-filter.c index 35e221e7ec8..fe2df82067f 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1884,7 +1884,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) struct object *obj; int i; - CALLOC_ARRAY(ref->value, used_atom_cnt); + ALLOC_ARRAY(ref->value, used_atom_cnt); if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) { ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING, @@ -1903,6 +1903,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) const char *refname; struct branch *branch = NULL; + v->s = NULL; v->s_size = ATOM_SIZE_UNSPECIFIED; v->handler = append_atom; v->atom = atom;