From patchwork Mon Aug 2 09:38:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12413645 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 78121C4338F for ; Mon, 2 Aug 2021 09:38:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60825610CC for ; Mon, 2 Aug 2021 09:38:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233113AbhHBJib (ORCPT ); Mon, 2 Aug 2021 05:38:31 -0400 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:36345 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233135AbhHBJi2 (ORCPT ); Mon, 2 Aug 2021 05:38:28 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id B8C983200805; Mon, 2 Aug 2021 05:38:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 02 Aug 2021 05:38:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=8GkTOAFn0SSq2MO4SLk6jkCnKOb FfR3Cb3wCmTUljaU=; b=pxv8c/+eIyAkakuqMk/IDVSh0eXKuMeIXMwv+CmJqqH LzaQhx3jfUlDeLLXt59tErp2+Q8Sc0euc4CN4Hxs8hJsSyiH8qlC3yrXnT96GxRf K7n1LZiOnLJ3CBq+/KTqS3AGsLxDhmTjI9sPUwGUX1WWq3rLD0aY1SIMd3VYg9bz ZhcdmVmJ+0V63Tch/bOYZDvD34rQEbWTpe490DYeqwbFwniGnWdNbek2IPY2sAUv mFA2n1Wvl9syyQ09UMu+SvZ/At9zdLqHMJURlurLjCq2La6d9nWFkCSydRe9NAB6 kK5mHWokNxuEMlY1k/z2mXvfnZHNrySDcqaAmNg609A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=8GkTOA Fn0SSq2MO4SLk6jkCnKObFfR3Cb3wCmTUljaU=; b=d0WFCts3OKreVcQ2FF9R+z JfY3c43829CKv7sjEnYgxeDZXnRlRSpUSuClFpAyXh3/PItfU6PSysk5a2IlgZWi 6f7vsGhDu/yNAgRb0fx93jzzNqgm4pWI00Rb/ShR3pj9DO2Rixb8gbmzyd6gTo+h XECz28QF6ArWhZYq8Y1SuF6NwZ90RGVX9Xjf2TrN89H+Pkp8O5o9RVltrkU//FTs mBxr9u6lrrpFNgVa8ZhFjOZOL9RZRLZnRm+K7iLDsxwnHR/QxKMVKK0DddUvnc7/ tteD7zqAJaoc7StRoAD/NO40vLJQuiGAcyNJoNJ6CwE3P1SCbC7w78km7fQH9A2A == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddriedvgdduhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtjeenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh ephefgjeeuveejteduhefgffefffdvjeefjeeivdekfffgkeeugfehveetueefleeknecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 2 Aug 2021 05:38:16 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 8c652bc7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 2 Aug 2021 09:38:16 +0000 (UTC) Date: Mon, 2 Aug 2021 11:38:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Felipe Contreras , SZEDER =?iso-8859-1?q?G=E1bor?= , Chris Torek , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Junio C Hamano , Taylor Blau Subject: [PATCH v3 4/4] revision: avoid hitting packfiles when commits are in commit-graph Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When queueing references in git-rev-list(1), we try to either reuse an already parsed object or alternatively we load the object header from disk in order to determine its type. This is inefficient for commits though in cases where we have a commit graph available: instead of hitting the real object on disk to determine its type, we may instead search the object graph for the object ID. In case it's found, we can directly fill in the commit object, otherwise we can still hit the disk to determine the object's type. Expose a new function `find_object_in_graph()`, which fills in an object of unknown type in case we find its object ID in the graph. This provides a big performance win in cases where there is a commit-graph available in the repository in case we load lots of references. The following has been executed in a real-world repository with about 2.2 million refs: Benchmark #1: HEAD~: rev-list --unsorted-input --objects --quiet --not --all --not $newrev Time (mean ± σ): 4.465 s ± 0.037 s [User: 4.144 s, System: 0.320 s] Range (min … max): 4.411 s … 4.514 s 10 runs Benchmark #2: HEAD: rev-list --unsorted-input --objects --quiet --not --all --not $newrev Time (mean ± σ): 2.886 s ± 0.032 s [User: 2.570 s, System: 0.316 s] Range (min … max): 2.826 s … 2.933 s 10 runs Summary 'HEAD: rev-list --unsorted-input --objects --quiet --not --all --not $newrev' ran 1.55 ± 0.02 times faster than 'HEAD~: rev-list --unsorted-input --objects --quiet --not --all --not $newrev' Signed-off-by: Patrick Steinhardt --- commit-graph.c | 55 +++++++++++++++++++++++++++++++++++++++----------- commit-graph.h | 2 ++ revision.c | 10 +++++---- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 3860a0d847..a81d5cebc0 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -864,6 +864,48 @@ static int fill_commit_in_graph(struct repository *r, return 1; } +static int find_object_id_in_graph(const struct object_id *id, struct commit_graph *g, uint32_t *pos) +{ + struct commit_graph *cur_g = g; + uint32_t lex_index; + + while (cur_g && !bsearch_graph(cur_g, (struct object_id *)id, &lex_index)) + cur_g = cur_g->base_graph; + + if (cur_g) { + *pos = lex_index + cur_g->num_commits_in_base; + return 1; + } + + return 0; +} + +int find_object_in_graph(struct repository *repo, struct object *object) +{ + struct commit *commit; + uint32_t pos; + + if (object->parsed) { + if (object->type != OBJ_COMMIT) + return -1; + return 0; + } + + if (!repo->objects->commit_graph) + return -1; + + if (!find_object_id_in_graph(&object->oid, repo->objects->commit_graph, &pos)) + return -1; + + commit = object_as_type(object, OBJ_COMMIT, 1); + if (!commit) + return -1; + if (!fill_commit_in_graph(repo, commit, repo->objects->commit_graph, pos)) + return -1; + + return 0; +} + static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t *pos) { uint32_t graph_pos = commit_graph_position(item); @@ -871,18 +913,7 @@ static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uin *pos = graph_pos; return 1; } else { - struct commit_graph *cur_g = g; - uint32_t lex_index; - - while (cur_g && !bsearch_graph(cur_g, &(item->object.oid), &lex_index)) - cur_g = cur_g->base_graph; - - if (cur_g) { - *pos = lex_index + cur_g->num_commits_in_base; - return 1; - } - - return 0; + return find_object_id_in_graph(&item->object.oid, g, pos); } } diff --git a/commit-graph.h b/commit-graph.h index 96c24fb577..f373fab4c0 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -139,6 +139,8 @@ int write_commit_graph(struct object_directory *odb, enum commit_graph_write_flags flags, const struct commit_graph_opts *opts); +int find_object_in_graph(struct repository *repo, struct object *object); + #define COMMIT_GRAPH_VERIFY_SHALLOW (1 << 0) int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags); diff --git a/revision.c b/revision.c index 671b6d6513..c3f9cf2998 100644 --- a/revision.c +++ b/revision.c @@ -362,10 +362,12 @@ static struct object *get_reference(struct rev_info *revs, const char *name, struct object *object = lookup_unknown_object(revs->repo, oid); if (object->type == OBJ_NONE) { - int type = oid_object_info(revs->repo, oid, NULL); - if (type < 0 || !object_as_type(object, type, 1)) { - object = NULL; - goto out; + if (find_object_in_graph(revs->repo, object) < 0) { + int type = oid_object_info(revs->repo, oid, NULL); + if (type < 0 || !object_as_type(object, type, 1)) { + object = NULL; + goto out; + } } }