git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
	Derrick Stolee <dstolee@microsoft.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>
Subject: Re: [PATCH v2 14/14] commit.h: delete 'util' field in struct commit
Date: Mon, 14 May 2018 18:07:38 +0200	[thread overview]
Message-ID: <20180514160738.GA19821@duynguyen.home> (raw)
In-Reply-To: <xmqqy3gmbrnm.fsf@gitster-ct.c.googlers.com>

On Mon, May 14, 2018 at 04:52:29PM +0900, Junio C Hamano wrote:
> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> 
> > diff --git a/commit.h b/commit.h
> > index 838f6a6b26..70371e111e 100644
> > --- a/commit.h
> > +++ b/commit.h
> > @@ -18,12 +18,16 @@ struct commit_list {
> >  
> >  struct commit {
> >  	struct object object;
> > -	void *util;
> >  	unsigned int index;
> >  	timestamp_t date;
> >  	struct commit_list *parents;
> >  	struct tree *tree;
> >  	uint32_t graph_pos;
> > +	/*
> > +	 * Do not add more fields here unless it's _very_ often
> > +	 * used. Use commit-slab to associate more data with a commit
> > +	 * instead.
> > +	 */
> >  };
> 
> That's a logical consequence and a natural endgame of this
> pleasent-to-read series.  THanks.
> 
> Unfortunately we are gaining more and more stuff in "struct commit"
> with recent topics, and we may want to see if we can evict some of
> them out to shrink it again.

Sigh.. ds/lazy-load-trees already enters 'next' so a fixup patch is
something like this.

Derrick, do you want to finish up this patch? I could do that by
myself, but I guess this could be good for you to get familiar with
commit-slab because ds/generation-numbers on 'pu' also adds a new
field in struct commit.

We should avoid adding more stuff in struct commit to reduce overhead
when these fields are not used (and I'm not sure how often generation
numbers are used to justify its place here). One clean way to do it is
with commit-slab, as demonstrated here for 'maybe_tree' field.

Anyway the patch is like this

-- 8< --
diff --git a/commit-graph.c b/commit-graph.c
index 70fa1b25fd..9d084f6200 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -9,6 +9,7 @@
 #include "revision.h"
 #include "sha1-lookup.h"
 #include "commit-graph.h"
+#include "commit-slab.h"
 
 #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
@@ -38,6 +39,26 @@
 #define GRAPH_MIN_SIZE (5 * GRAPH_CHUNKLOOKUP_WIDTH + GRAPH_FANOUT_SIZE + \
 			GRAPH_OID_LEN + 8)
 
+
+/*
+ * If the commit is loaded from the commit-graph file, then this
+ * member may be NULL. Only access it through get_commit_tree()
+ * or get_commit_tree_oid().
+ */
+define_commit_slab(maybe_tree, struct tree *);
+struct maybe_tree maybe_trees = COMMIT_SLAB_INIT(1, maybe_trees);
+
+struct tree *set_maybe_tree(const struct commit *commit, struct tree *tree)
+{
+	*maybe_tree_at(&maybe_trees, commit) = tree;
+	return tree;
+}
+
+struct tree *get_maybe_tree(const struct commit *commit)
+{
+	return *maybe_tree_at(&maybe_trees, commit);
+}
+
 char *get_commit_graph_filename(const char *obj_dir)
 {
 	return xstrfmt("%s/info/commit-graph", obj_dir);
@@ -256,7 +277,7 @@ static int fill_commit_in_graph(struct commit *item, struct commit_graph *g, uin
 	item->object.parsed = 1;
 	item->graph_pos = pos;
 
-	item->maybe_tree = NULL;
+	set_maybe_tree(item, NULL);
 
 	date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
 	date_low = get_be32(commit_data + g->hash_len + 12);
@@ -322,15 +343,15 @@ static struct tree *load_tree_for_commit(struct commit_graph *g, struct commit *
 					   GRAPH_DATA_WIDTH * (c->graph_pos);
 
 	hashcpy(oid.hash, commit_data);
-	c->maybe_tree = lookup_tree(&oid);
-
-	return c->maybe_tree;
+	return set_maybe_tree(c, lookup_tree(&oid));
 }
 
 struct tree *get_commit_tree_in_graph(const struct commit *c)
 {
-	if (c->maybe_tree)
-		return c->maybe_tree;
+	struct tree *maybe_tree = get_maybe_tree(c);
+
+	if (maybe_tree)
+		return maybe_tree;
 	if (c->graph_pos == COMMIT_NOT_FROM_GRAPH)
 		BUG("get_commit_tree_in_graph called from non-commit-graph commit");
 
diff --git a/commit-graph.h b/commit-graph.h
index 260a468e73..4a02e4b05e 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -45,4 +45,7 @@ void write_commit_graph(const char *obj_dir,
 			int nr_commits,
 			int append);
 
+struct tree *set_maybe_tree(const struct commit *commit, struct tree *tree);
+struct tree *get_maybe_tree(const struct commit *commit);
+
 #endif
diff --git a/commit.c b/commit.c
index 711f674c18..45521ab2de 100644
--- a/commit.c
+++ b/commit.c
@@ -298,8 +298,10 @@ void free_commit_buffer(struct commit *commit)
 
 struct tree *get_commit_tree(const struct commit *commit)
 {
-	if (commit->maybe_tree || !commit->object.parsed)
-		return commit->maybe_tree;
+	struct tree *maybe_tree = get_maybe_tree(commit);
+
+	if (maybe_tree || !commit->object.parsed)
+		return maybe_tree;
 
 	if (commit->graph_pos == COMMIT_NOT_FROM_GRAPH)
 		BUG("commit has NULL tree, but was not loaded from commit-graph");
@@ -351,7 +353,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
 	if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
 		return error("bad tree pointer in commit %s",
 			     oid_to_hex(&item->object.oid));
-	item->maybe_tree = lookup_tree(&parent);
+	set_maybe_tree(item, lookup_tree(&parent));
 	bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
 	pptr = &item->parents;
 
diff --git a/commit.h b/commit.h
index 23a3f364ed..b7274ca365 100644
--- a/commit.h
+++ b/commit.h
@@ -22,13 +22,6 @@ struct commit {
 	unsigned int index;
 	timestamp_t date;
 	struct commit_list *parents;
-
-	/*
-	 * If the commit is loaded from the commit-graph file, then this
-	 * member may be NULL. Only access it through get_commit_tree()
-	 * or get_commit_tree_oid().
-	 */
-	struct tree *maybe_tree;
 	uint32_t graph_pos;
 };
 
diff --git a/merge-recursive.c b/merge-recursive.c
index 8de6e36527..a8b5f9ca39 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -23,6 +23,7 @@
 #include "merge-recursive.h"
 #include "dir.h"
 #include "submodule.h"
+#include "commit-graph.h"
 
 struct path_hashmap_entry {
 	struct hashmap_entry e;
@@ -101,7 +102,7 @@ static struct commit *make_virtual_commit(struct tree *tree, const char *comment
 	struct commit *commit = alloc_commit_node();
 
 	set_merge_remote_desc(commit, comment, (struct object *)commit);
-	commit->maybe_tree = tree;
+	set_maybe_tree(commit, tree);
 	commit->object.parsed = 1;
 	return commit;
 }
-- 8< --



  reply	other threads:[~2018-05-14 16:08 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-12  8:00 [PATCH 00/12] Die commit->util, die! Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 01/12] blame: use commit-slab for blame suspects instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-12  9:22   ` Jeff King
2018-05-12 12:13     ` Duy Nguyen
2018-05-12  8:00 ` [PATCH 02/12] describe: use commit-slab for commit names " Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 03/12] shallow.c: use commit-slab for commit depth " Nguyễn Thái Ngọc Duy
2018-05-12  9:07   ` Jeff King
2018-05-12  9:18     ` Jeff King
2018-05-12 12:09       ` Duy Nguyen
2018-05-12 19:12         ` Jeff King
2018-05-12 11:59     ` Duy Nguyen
2018-05-12  8:00 ` [PATCH 04/12] sequencer.c: use commit-slab to mark seen commits Nguyễn Thái Ngọc Duy
2018-05-12  9:25   ` Jeff King
2018-05-12 13:43     ` Junio C Hamano
2018-05-12 14:00       ` Duy Nguyen
2018-05-12  8:00 ` [PATCH 05/12] sequencer.c: use commit-slab to associate todo items to commits Nguyễn Thái Ngọc Duy
2018-05-12  9:28   ` Jeff King
2018-05-12  8:00 ` [PATCH 06/12] revision.c: use commit-slab for show_source Nguyễn Thái Ngọc Duy
2018-05-12  9:33   ` Jeff King
2018-05-12 13:58     ` Junio C Hamano
2018-05-12 14:13       ` Duy Nguyen
2018-05-12 19:06         ` Jeff King
2018-05-12  8:00 ` [PATCH 07/12] bisect.c: use commit-slab for commit weight instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-12 13:59   ` Junio C Hamano
2018-05-12  8:00 ` [PATCH 08/12] name-rev: use commit-slab for rev-name " Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 09/12] show-branch: use commit-slab for commit-name " Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 10/12] log: use commit-slab in prepare_bases() " Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 11/12] merge: use commit-slab in merge remote desc " Nguyễn Thái Ngọc Duy
2018-05-12  8:00 ` [PATCH 12/12] commit.h: delete 'util' field in struct commit Nguyễn Thái Ngọc Duy
2018-05-12  9:41 ` [PATCH 00/12] Die commit->util, die! Jeff King
2018-05-12 18:50 ` Jakub Narebski
2018-05-13  5:39   ` Duy Nguyen
2018-05-13  5:51 ` [PATCH v2 00/14] " Nguyễn Thái Ngọc Duy
2018-05-13  5:51   ` [PATCH v2 01/14] commit-slab.h: code split Nguyễn Thái Ngọc Duy
2018-05-13 23:33     ` Junio C Hamano
2018-05-13  5:51   ` [PATCH v2 02/14] commit-slab: support shared commit-slab Nguyễn Thái Ngọc Duy
2018-05-13 23:36     ` Junio C Hamano
2018-05-13  5:51   ` [PATCH v2 03/14] blame: use commit-slab for blame suspects instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-13 23:42     ` Junio C Hamano
2018-05-13  5:51   ` [PATCH v2 04/14] describe: use commit-slab for commit names " Nguyễn Thái Ngọc Duy
2018-05-13 23:45     ` Junio C Hamano
2018-05-13  5:51   ` [PATCH v2 05/14] shallow.c: use commit-slab for commit depth " Nguyễn Thái Ngọc Duy
2018-05-13  5:52   ` [PATCH v2 06/14] sequencer.c: use commit-slab to mark seen commits Nguyễn Thái Ngọc Duy
2018-05-14  4:17     ` Junio C Hamano
2018-05-13  5:52   ` [PATCH v2 07/14] sequencer.c: use commit-slab to associate todo items to commits Nguyễn Thái Ngọc Duy
2018-05-13  5:52   ` [PATCH v2 08/14] revision.c: use commit-slab for show_source Nguyễn Thái Ngọc Duy
2018-05-14  5:10     ` Junio C Hamano
2018-05-14  5:37       ` Junio C Hamano
2018-05-13  5:52   ` [PATCH v2 09/14] bisect.c: use commit-slab for commit weight instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-14  6:16     ` Junio C Hamano
2018-05-13  5:52   ` [PATCH v2 10/14] name-rev: use commit-slab for rev-name " Nguyễn Thái Ngọc Duy
2018-05-13  5:52   ` [PATCH v2 11/14] show-branch: use commit-slab for commit-name " Nguyễn Thái Ngọc Duy
2018-05-14  6:45     ` Junio C Hamano
2018-05-19  4:51       ` Duy Nguyen
2018-05-13  5:52   ` [PATCH v2 12/14] log: use commit-slab in prepare_bases() " Nguyễn Thái Ngọc Duy
2018-05-13  5:52   ` [PATCH v2 13/14] merge: use commit-slab in merge remote desc " Nguyễn Thái Ngọc Duy
2018-05-18  2:16     ` Junio C Hamano
2018-05-18 17:54       ` Ramsay Jones
2018-05-13  5:52   ` [PATCH v2 14/14] commit.h: delete 'util' field in struct commit Nguyễn Thái Ngọc Duy
2018-05-14  7:52     ` Junio C Hamano
2018-05-14 16:07       ` Duy Nguyen [this message]
2018-05-14 17:30         ` Duy Nguyen
2018-05-14 18:14           ` Derrick Stolee
2018-05-19  5:41             ` Duy Nguyen
2018-05-19  5:28   ` [PATCH v3 00/15] Die commit->util, die! Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 01/15] commit-slab.h: code split Nguyễn Thái Ngọc Duy
2018-05-21  5:11       ` Junio C Hamano
2018-05-19  5:28     ` [PATCH v3 02/15] commit-slab: support shared commit-slab Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 03/15] blame: use commit-slab for blame suspects instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 04/15] describe: use commit-slab for commit names " Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 05/15] shallow.c: use commit-slab for commit depth " Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 06/15] sequencer.c: use commit-slab to mark seen commits Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 07/15] sequencer.c: use commit-slab to associate todo items to commits Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 08/15] revision.c: use commit-slab for show_source Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 09/15] bisect.c: use commit-slab for commit weight instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 10/15] name-rev: use commit-slab for rev-name " Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 11/15] show-branch: use commit-slab for commit-name " Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 12/15] show-branch: note about its object flags usage Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 13/15] log: use commit-slab in prepare_bases() instead of commit->util Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 14/15] merge: use commit-slab in merge remote desc " Nguyễn Thái Ngọc Duy
2018-05-19  5:28     ` [PATCH v3 15/15] commit.h: delete 'util' field in struct commit Nguyễn Thái Ngọc Duy
2018-05-22 22:40 ` [PATCH 00/12] Die commit->util, die! Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180514160738.GA19821@duynguyen.home \
    --to=pclouds@gmail.com \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).