git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/3] treewide: switch to khashl for memory savings

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 26, 2024, 17:48 UTC
Message-ID
<xmqqttksanpj.fsf@gitster.g>
In-Reply-To
<20240325230704.262272-3-e@80x24.org>
Eric Wong <e@80x24.org> writes:
Show 6 quoted lines
> khashl is an updated version of khash with less memory overhead
> (one bit/bucket instead of two) than the original khash and
> similar overall performance.  Insertions are simpler (linear
> probing) but deletions may be slightly slower[1].  Of course,
> the majority of hash tables in git do not delete individual
> elements.
$ make builtin/fast-import.sp ;# part of make sparse
    SP builtin/fast-import.c
builtin/fast-import.c: note: in included file (through oidset.h, packfile.h):
khashl.h:516:1: error: Using plain integer as NULL pointer
khashl.h:516:1: error: Using plain integer as NULL pointer
make: *** [Makefile:3237: builtin/fast-import.sp] Error 1

I found IMPL_GET and IMPL_DEL's use of (h->keys == 0) were giving one of these two, and managed to reduce the error to just one with the attached patch, but I don't know what the other error is coming from.

 khashl.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git c/khashl.h w/khashl.h
index 8ffe80fbb2..663e36cd2d 100644
--- c/khashl.h
+++ w/khashl.h
@@ -101,7 +101,7 @@ static kh_inline khint_t __kh_h2b(khint_t hash, khint_t bits) { return hash * 26
 #define __KHASHL_IMPL_GET(SCOPE, HType, prefix, khkey_t, __hash_fn, __hash_eq) \
 	SCOPE khint_t prefix##_getp_core(const HType *h, const khkey_t *key, khint_t hash) { \
 		khint_t i, last, n_buckets, mask; \
-		if (h->keys == 0) return 0; \
+		if (!h->keys) return 0; \
 		n_buckets = (khint_t)1U << h->bits; \
 		mask = n_buckets - 1U; \
 		i = last = __kh_h2b(hash, h->bits); \
@@ -183,7 +183,7 @@ static kh_inline khint_t __kh_h2b(khint_t hash, khint_t bits) { return hash * 26
 #define __KHASHL_IMPL_DEL(SCOPE, HType, prefix, khkey_t, __hash_fn) \
 	SCOPE int prefix##_del(HType *h, khint_t i) { \
 		khint_t j = i, k, mask, n_buckets; \
-		if (h->keys == 0) return 0; \
+		if (!h->keys) return 0; \
 		n_buckets = (khint_t)1U<<h->bits; \
 		mask = n_buckets - 1U; \
 		while (1) { \



	
Previous: Eric WongNext: Jeff King
Message 4 of 11 in “switch to tombstone-free khashl table”
  1. 0/3 switch to tombstone-free khashl tableEric Wong, Mar 25, 2024
  2. 1/3 list-objects-filter: use kh_size APIEric Wong, Mar 25, 2024
  3. 2/3 treewide: switch to khashl for memory savingsEric Wong, Mar 25, 2024
  4. Junio C HamanoMar 26, 2024
  5. Jeff KingMar 27, 2024
  6. Junio C HamanoMar 27, 2024
  7. 3/3 khashl: fix ensemble lookups on empty tableEric Wong, Mar 25, 2024
  8. 4/3 switch to khashl ensembleEric Wong, Mar 25, 2024
  9. Junio C HamanoMar 26, 2024
  10. Junio C HamanoApr 19, 2024
  11. Eric WongApr 19, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.