git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hash: reduce size of algo member of object ID
@ 2021-10-03  5:51 René Scharfe
  2021-10-04  7:31 ` Eric Wong
  2021-10-04  8:13 ` Jeff King
  0 siblings, 2 replies; 7+ messages in thread
From: René Scharfe @ 2021-10-03  5:51 UTC (permalink / raw)
  To: Git List
  Cc: Andrzej Hunt, Eric Wong, Jeff King, Junio C Hamano,
	Carlo Marcelo Arenas Belón, brian m. carlson

cf0983213c (hash: add an algo member to struct object_id, 2021-04-26)
introduced the algo member as an int.  This increased the size of struct
object_id by 4 bytes (12.5%) and imposed a 4-byte alignment.  Currently
we only need to stored the values 0, 1 and 2 in it.  Let's use an
unsigned char instead to reduce the size overhead and lift the alignment
requirement.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
Not sure how to measure the performance impact of this change.  The perf
tests mentioned by cf0983213c don't show much of a difference with
GIT_PERF_REPEAT_COUNT=10 for me:

Test                                             origin/master       HEAD
--------------------------------------------------------------------------------------------
0001.1: rev-list --all                           0.11(0.08+0.02)     0.11(0.08+0.02) +0.0%
0001.2: rev-list --all --objects                 3.04(2.98+0.05)     3.04(2.98+0.05) +0.0%
0001.3: rev-list --parents                       0.05(0.04+0.01)     0.05(0.03+0.01) +0.0%
0001.5: rev-list -- dummy                        0.21(0.20+0.01)     0.21(0.19+0.01) +0.0%
0001.6: rev-list --parents -- dummy              0.22(0.20+0.01)     0.22(0.20+0.01) +0.0%
0001.8: rev-list $commit --not --all             0.06(0.05+0.00)     0.06(0.05+0.00) +0.0%
0001.9: rev-list --objects $commit --not --all   0.06(0.05+0.00)     0.06(0.05+0.00) +0.0%
1450.1: fsck                                     20.20(19.71+0.47)   20.18(19.70+0.48) -0.1%

 hash.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hash.h b/hash.h
index 9e25c40e9a..24d8f7cd21 100644
--- a/hash.h
+++ b/hash.h
@@ -115,7 +115,7 @@ static inline void git_SHA256_Clone(git_SHA256_CTX *dst, const git_SHA256_CTX *s

 struct object_id {
 	unsigned char hash[GIT_MAX_RAWSZ];
-	int algo;	/* XXX requires 4-byte alignment */
+	unsigned char algo;
 };

 /* A suitably aligned type for stack allocations of hash contexts. */
--
2.33.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-10-05 17:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-03  5:51 [PATCH] hash: reduce size of algo member of object ID René Scharfe
2021-10-04  7:31 ` Eric Wong
2021-10-04  8:13 ` Jeff King
2021-10-04  8:20   ` Jeff King
2021-10-05  0:04     ` brian m. carlson
2021-10-05 17:28     ` René Scharfe
2021-10-04  8:47   ` Ævar Arnfjörð Bjarmason

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).