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

Re: [PATCH 3/3] Use struct tree in diff-tree

From
Linus Torvalds <torvalds@osdl.org>
Date
Jan 31, 2006, 16:53 UTC
Message-ID
<Pine.LNX.4.64.0601310846380.7301@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0601291405250.25300@iabervon.org>
On Sun, 29 Jan 2006, Daniel Barkalow wrote:
>
> It had been open-coding a tree parser. This updates the programs that
> call diff_tree() to send it the struct tree instead of a buffer and
> size.
Please don't.
parse_tree() is extremely broken, and expensive. 

The "struct tree_desc" is a much better abstraction, and avoids all overhead. Yes, it's slightly more opaque, and the interfaces could be improved: for example, instead of having a

	desc.buf = read_object_with_reference(new, "tree", &desc.size, NULL);
	if (!desc.buf)
		die("unable to read tree");

it might make make sense to introduce a function that does this for you, ie just a

	if (populate_tree_descriptor(new, &desc) < 0)
		die("unable to read tree");
	...
	free_tree_descriptor(&desc);
which is perhaps more readable and maintainable.

The "diff_tree()" functions are _extremely_ performance-critical, arguably more so than _any_ other part of git. Diffing two trees is one of _the_ most common operations, especially so when you want to follow just a subset of files with "git-rev-list -- <filename>*", and it's extremely important that you don't do malloc()/free() all the time.

So using "struct tree" and the general tree-parsing functions is _wrong_. Really REALLY wrong.

>From what I can tell, your version doesn't even do the "free()". Which 

probably means that not only is it slower, but I bet that if you have a big repository like the kernel, and you do a slightly more complex git-rev-list with multiple files, you'll use up tons and tons and tons of memory.

Junio, please don't apply this.
		Linus
Previous: Daniel BarkalowNext: Junio C Hamano
Message 5 of 11 in “Remove more parsers”
  1. 0/3 Remove more parsersDaniel Barkalow, Jan 29, 2006
  2. 1/3 Use struct tree in tar-treeDaniel Barkalow, Jan 29, 2006
  3. 2/3 Use struct commit in tar-treeDaniel Barkalow, Jan 29, 2006
  4. 3/3 Use struct tree in diff-treeDaniel Barkalow, Jan 29, 2006
  5. Linus TorvaldsJan 31, 2006
  6. Junio C HamanoJan 31, 2006
  7. Daniel BarkalowJan 31, 2006
  8. Linus TorvaldsJan 31, 2006
  9. Junio C HamanoJan 29, 2006
  10. Daniel BarkalowJan 29, 2006
  11. Linus TorvaldsJan 31, 2006

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.