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

Re: [PATCH v2 5/5] oidtree: a crit-bit tree for odb_loose_cache

From
EWEric Wong <e@80x24.org>
Date
Jul 7, 2021, 23:12 UTC
Message-ID
<20210707231222.GA27550@dcvr>
In-Reply-To
<87zgv276lf.fsf@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
Show 8 quoted lines
> 
> On Tue, Jun 29 2021, Eric Wong wrote:
> 
> > +struct alloc_state;
> > +struct oidtree {
> > +	struct cb_tree t;
> 
> s/t/tree/? Too short a name for an interface IMO.

Done. I was keeping `t' to match agl's published version (and it remains that way in cbtree.[ch])

Show 12 quoted lines
> > +	struct alloc_state *mempool;
> > +};
> > +
> > +#define OIDTREE_INIT { .t = CBTREE_INIT, .mempool = NULL }
> 
> Let's use designated initilaizers for new code. Just:
> 
> 	#define OIDTREE_init { \
> 		.tere = CBTREE_INIT, \
> 	}
> 
> Will do, no need for the ".mempool = NULL"
Show 10 quoted lines
> > +static inline void oidtree_init(struct oidtree *ot)
> > +{
> > +	cb_init(&ot->t);
> > +	ot->mempool = NULL;
> > +}
> 
> You can use the "memcpy() a blank" trick/idiom here:
> https://lore.kernel.org/git/patch-2.5-955dbd1693d-20210701T104855Z-avarab@gmail.com/
> 
> Also, is this even needed? Why have the "destroy" re-initialize it?

I'm using mem_pool, now. With the way mem_pool_init works, I've decided to do away with OIDTREE_INIT and only use oidtree_init (and lazy-malloc the entire loose_objects_cache)

> > +void oidtree_destroy(struct oidtree *);
> 
> Maybe s/destroy/release/, or if you actually need that reset behavior
> oidtree_reset(). We've got
I'm renaming it oidtree_clear to match oid_array_clear.
Show 7 quoted lines
> > +void oidtree_insert(struct oidtree *, const struct object_id *);
> > +int oidtree_contains(struct oidtree *, const struct object_id *);
> > +
> > +typedef enum cb_next (*oidtree_iter)(const struct object_id *, void *arg);
> 
> An "arg" name for some arguments, but none for others, if there's a name
> here call it "data" like you do elswhere?

OK, using "data". To reduce noise, I prefer to only name variables in prototypes if the usage can't be easily inferred from its type and function name.

> > +void oidtree_each(struct oidtree *, const struct object_id *,
> > +			size_t oidhexlen, oidtree_iter, void *arg);
> 
> s/oidhexlen/hexsz/, like in git_hash_algo.a
done
Show 42 quoted lines
> > +++ b/t/helper/test-oidtree.c
> > @@ -0,0 +1,47 @@
> > +#include "test-tool.h"
> > +#include "cache.h"
> > +#include "oidtree.h"
> > +
> > +static enum cb_next print_oid(const struct object_id *oid, void *data)
> > +{
> > +	puts(oid_to_hex(oid));
> > +	return CB_CONTINUE;
> > +}
> > +
> > +int cmd__oidtree(int argc, const char **argv)
> > +{
> > +	struct oidtree ot = OIDTREE_INIT;
> > +	struct strbuf line = STRBUF_INIT;
> > +	int nongit_ok;
> > +	int algo = GIT_HASH_UNKNOWN;
> > +
> > +	setup_git_directory_gently(&nongit_ok);
> > +
> > +	while (strbuf_getline(&line, stdin) != EOF) {
> > +		const char *arg;
> > +		struct object_id oid;
> > +
> > +		if (skip_prefix(line.buf, "insert ", &arg)) {
> > +			if (get_oid_hex_any(arg, &oid) == GIT_HASH_UNKNOWN)
> > +				die("insert not a hexadecimal oid: %s", arg);
> > +			algo = oid.algo;
> > +			oidtree_insert(&ot, &oid);
> > +		} else if (skip_prefix(line.buf, "contains ", &arg)) {
> > +			if (get_oid_hex(arg, &oid))
> > +				die("contains not a hexadecimal oid: %s", arg);
> > +			printf("%d\n", oidtree_contains(&ot, &oid));
> > +		} else if (skip_prefix(line.buf, "each ", &arg)) {
> > +			char buf[GIT_MAX_HEXSZ + 1] = { '0' };
> > +			memset(&oid, 0, sizeof(oid));
> > +			memcpy(buf, arg, strlen(arg));
> > +			buf[hash_algos[algo].hexsz] = 0;
> 
> = '\0' if it's the intent to have a NULL-terminated string is more
> readable.
done
Show 9 quoted lines
> > +			get_oid_hex_any(buf, &oid);
> > +			oid.algo = algo;
> > +			oidtree_each(&ot, &oid, strlen(arg), print_oid, NULL);
> > +		} else if (!strcmp(line.buf, "destroy"))
> > +			oidtree_destroy(&ot);
> > +		else
> > +			die("unknown command: %s", line.buf);
> 
> Missing braces.
Added.
Show 57 quoted lines
> > +	}
> > +	return 0;
> > +}
> > diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
> > index c5bd0c6d4c..9d37debf28 100644
> > --- a/t/helper/test-tool.c
> > +++ b/t/helper/test-tool.c
> > @@ -43,6 +43,7 @@ static struct test_cmd cmds[] = {
> >  	{ "mktemp", cmd__mktemp },
> >  	{ "oid-array", cmd__oid_array },
> >  	{ "oidmap", cmd__oidmap },
> > +	{ "oidtree", cmd__oidtree },
> >  	{ "online-cpus", cmd__online_cpus },
> >  	{ "parse-options", cmd__parse_options },
> >  	{ "parse-pathspec-file", cmd__parse_pathspec_file },
> > diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
> > index e8069a3b22..f683a2f59c 100644
> > --- a/t/helper/test-tool.h
> > +++ b/t/helper/test-tool.h
> > @@ -32,6 +32,7 @@ int cmd__match_trees(int argc, const char **argv);
> >  int cmd__mergesort(int argc, const char **argv);
> >  int cmd__mktemp(int argc, const char **argv);
> >  int cmd__oidmap(int argc, const char **argv);
> > +int cmd__oidtree(int argc, const char **argv);
> >  int cmd__online_cpus(int argc, const char **argv);
> >  int cmd__parse_options(int argc, const char **argv);
> >  int cmd__parse_pathspec_file(int argc, const char** argv);
> > diff --git a/t/t0069-oidtree.sh b/t/t0069-oidtree.sh
> > new file mode 100755
> > index 0000000000..0594f57c81
> > --- /dev/null
> > +++ b/t/t0069-oidtree.sh
> > @@ -0,0 +1,52 @@
> > +#!/bin/sh
> > +
> > +test_description='basic tests for the oidtree implementation'
> > +. ./test-lib.sh
> > +
> > +echoid () {
> > +	prefix="${1:+$1 }"
> > +	shift
> > +	while test $# -gt 0
> > +	do
> > +		echo "$1"
> > +		shift
> > +	done | awk -v prefix="$prefix" -v ZERO_OID=$ZERO_OID '{
> > +		printf("%s%s", prefix, $0);
> > +		need = length(ZERO_OID) - length($0);
> > +		for (i = 0; i < need; i++)
> > +			printf("0");
> > +		printf "\n";
> > +	}'
> > +}
> 
> Looks fairly easy to do in pure-shell, first of all you don't need a
> length() on $ZERO_OID, use $(test_oid hexsz) instead. That applies for
> the awk version too.
Ah, I didn't know about test_oid, using it, now.
> But once you have that and the N arguments just do a wc -c on the
> argument, use $(()) to compute the $difference, and a loop with:
> 
>     printf "%s%s%0${difference}d" "$prefix" "$shortoid" "0"

I also wanted to avoid repeated 'wc -c' and figured awk was portable enough since we use it elsewhere in tests. I've now noticed "${#var}" is portable and we're already relying on it in packetize(), so I'm using that.

Show 12 quoted lines
> > +
> > +test_expect_success 'oidtree insert and contains' '
> > +	cat >expect <<EOF &&
> > +0
> > +0
> > +0
> > +1
> > +1
> > +0
> > +EOF
> 
> use "<<-\EOF" and indent it.
done
Thanks all for the reviews.
Previous: Ævar Arnfjörð BjarmasonNext: Andrzej Hunt
Message 34 of 99 in “speed up alt_odb_usable() with many alternates”
  1. speed up alt_odb_usable() with many alternatesEric Wong, Jun 24, 2021
  2. 0/5 optimizations for many odb alternatesEric Wong, Jun 27, 2021
  3. 2/5 avoid strlen via strbuf_addstr in link_alt_odb_entryEric Wong, Jun 27, 2021
  4. 1/5 speed up alt_odb_usable() with many alternatesEric Wong, Jun 27, 2021
  5. 3/5 make object_directory.loose_objects_subdir_seen a bitmapEric Wong, Jun 27, 2021
  6. René ScharfeJun 27, 2021
  7. Eric WongJun 28, 2021
  8. 4/5 oidcpy_with_padding: constify `src' argEric Wong, Jun 27, 2021
  9. 5/5 oidtree: a crit-bit tree for odb_loose_cacheEric Wong, Jun 27, 2021
  10. Junio C HamanoJun 29, 2021
  11. Eric WongJun 29, 2021
  12. 0/5 optimizations for many alternatesEric Wong, Jun 29, 2021
  13. 0/5 optimizations for many alternatesEric Wong, Jul 7, 2021
  14. 1/5 speed up alt_odb_usable() with many alternatesEric Wong, Jul 7, 2021
  15. Junio C HamanoJul 8, 2021
  16. Eric WongJul 8, 2021
  17. Junio C HamanoJul 8, 2021
  18. 2/5 avoid strlen via strbuf_addstr in link_alt_odb_entryEric Wong, Jul 7, 2021
  19. Junio C HamanoJul 8, 2021
  20. 3/5 make object_directory.loose_objects_subdir_seen a bitmapEric Wong, Jul 7, 2021
  21. 4/5 oidcpy_with_padding: constify `src' argEric Wong, Jul 7, 2021
  22. 5/5 oidtree: a crit-bit tree for odb_loose_cacheEric Wong, Jul 7, 2021
  23. 1/5 speed up alt_odb_usable() with many alternatesEric Wong, Jun 29, 2021
  24. René ScharfeJul 3, 2021
  25. René ScharfeJul 4, 2021
  26. Eric WongJul 6, 2021
  27. 2/5 avoid strlen via strbuf_addstr in link_alt_odb_entryEric Wong, Jun 29, 2021
  28. 3/5 make object_directory.loose_objects_subdir_seen a bitmapEric Wong, Jun 29, 2021
  29. 4/5 oidcpy_with_padding: constify `src' argEric Wong, Jun 29, 2021
  30. 5/5 oidtree: a crit-bit tree for odb_loose_cacheEric Wong, Jun 29, 2021
  31. René ScharfeJul 4, 2021
  32. Eric WongJul 6, 2021
  33. Ævar Arnfjörð BjarmasonJul 4, 2021
  34. Eric WongJul 7, 2021
  35. Andrzej HuntAug 6, 2021
  36. René ScharfeAug 6, 2021
  37. Eric WongAug 7, 2021
  38. Carlo ArenasAug 9, 2021
  39. 0/3 pedantic errors in nextCarlo Marcelo Arenas Belón, Aug 9, 2021
  40. 2/3 object-store: avoid extra ';' from KHASH_INITCarlo Marcelo Arenas Belón, Aug 9, 2021
  41. Junio C HamanoAug 9, 2021
  42. 1/3 oidtree: avoid nested struct oidtree_nodeCarlo Marcelo Arenas Belón, Aug 9, 2021
  43. 3/3 ci: run a pedantic build as part of the GitHub workflowCarlo Marcelo Arenas Belón, Aug 9, 2021
  44. Bagas SanjayaAug 9, 2021
  45. Carlo ArenasAug 9, 2021
  46. Phillip WoodAug 9, 2021
  47. Carlo ArenasAug 9, 2021
  48. Phillip WoodAug 10, 2021
  49. Junio C HamanoAug 10, 2021
  50. Ævar Arnfjörð BjarmasonAug 30, 2021
  51. Carlo ArenasAug 31, 2021
  52. Ævar Arnfjörð BjarmasonAug 31, 2021
  53. Carlo ArenasAug 31, 2021
  54. Jeff KingSep 1, 2021
  55. Junio C HamanoSep 1, 2021
  56. Ævar Arnfjörð BjarmasonAug 30, 2021
  57. 0/4 developer: support pedanticCarlo Marcelo Arenas Belón, Sep 1, 2021
  58. 1/4 developer: retire USE_PARENS_AROUND_GETTEXT_N supportCarlo Marcelo Arenas Belón, Sep 1, 2021
  59. 2/4 developer: enable pedantic by defaultCarlo Marcelo Arenas Belón, Sep 1, 2021
  60. 3/4 developer: add an alternative script for detecting broken N_()Carlo Marcelo Arenas Belón, Sep 1, 2021
  61. 4/4 developer: move detect-compiler out of the main directoryCarlo Marcelo Arenas Belón, Sep 1, 2021
  62. Jeff KingSep 1, 2021
  63. gettext: remove optional non-standard parens in N_() definitionÆvar Arnfjörð Bjarmason, Sep 1, 2021
  64. Eric SunshineSep 1, 2021
  65. Jeff KingSep 2, 2021
  66. Junio C HamanoSep 2, 2021
  67. Ævar Arnfjörð BjarmasonSep 1, 2021
  68. Carlo ArenasSep 1, 2021
  69. 0/3 support pedantic in developer modeCarlo Marcelo Arenas Belón, Sep 3, 2021
  70. 1/3 gettext: remove optional non-standard parens in N_() definitionCarlo Marcelo Arenas Belón, Sep 3, 2021
  71. Ævar Arnfjörð BjarmasonSep 10, 2021
  72. 2/3 win32: allow building with pedantic mode enabledCarlo Marcelo Arenas Belón, Sep 3, 2021
  73. René ScharfeSep 3, 2021
  74. Carlo Marcelo Arenas BelónSep 3, 2021
  75. Junio C HamanoSep 3, 2021
  76. René ScharfeSep 3, 2021
  77. René ScharfeSep 4, 2021
  78. Carlo ArenasSep 4, 2021
  79. Jonathan TanSep 27, 2021
  80. Carlo ArenasSep 28, 2021
  81. Jonathan TanSep 28, 2021
  82. Junio C HamanoSep 28, 2021
  83. Jonathan TanSep 28, 2021
  84. Carlo ArenasSep 29, 2021
  85. Junio C HamanoSep 29, 2021
  86. 3/3 developer: enable pedantic by defaultCarlo Marcelo Arenas Belón, Sep 3, 2021
  87. Ævar Arnfjörð BjarmasonSep 5, 2021
  88. Junio C HamanoAug 9, 2021
  89. Eric WongAug 9, 2021
  90. Carlo Marcelo Arenas BelónAug 10, 2021
  91. René ScharfeAug 10, 2021
  92. Carlo ArenasAug 10, 2021
  93. Carlo ArenasAug 11, 2021
  94. René ScharfeAug 11, 2021
  95. Junio C HamanoAug 11, 2021
  96. René ScharfeAug 10, 2021
  97. René ScharfeAug 10, 2021
  98. oidtree: avoid unaligned access to crit-bit treeRené Scharfe, Aug 14, 2021
  99. Junio C HamanoAug 16, 2021

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.