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

Re: [PATCH v3 3/3] index-pack: support multithreaded delta resolving

From
Junio C Hamano <gitster@pobox.com>
Date
May 4, 2012, 15:23 UTC
Message-ID
<7v8vh8c6mx.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CACsJy8DHtBZdhoh1BPwn2_-3wVDRWypJOg3kR9wjd2o1bLUW-Q@mail.gmail.com>
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
> Junio, can you make a patch (or update current ones) with better
> naming? I obviously did not see why these names were bad. You may
> provide more convincing explanation than me in the commit message.
I have already explained s/nr_processed/nr_dispatched/.

I do not think second_pass vs threaded_second_pass is merely a naming issue. The code structure ("taking the abstraction backwards") is the bigger issue.

The original before the series has:
	parse_pack_objects()
	{
		... a lot of code for the first pass ...
		
		... a lot of code for the second pass which looks like
		for (all object entries) {
			set global state base_obj->obj to it
			find unresolved deltas for that single base_obj
			display progress
		}
	}
and you first split one iteration of the second pass, resulting in
	parse_pack_objects()
	{
		... a lot of code for the first pass ...
		
		for (all object entries) {
			set global state base_obj->obj to it
			second_pass()
		}
	}

which I think is a wrong way to do it, because here is what your next step ends up with because of that:

	parse_pack_objects()
	{
		... a lot of code for the first pass ...
		
	#if WE SUPPORT THREADING
		for (number of threads we are going to spawn) {
			spawn thread and let it run threaded_second_pass
		}
		for (all threads) {
			cull them when they are done
		}
		return
	#endif
		... when not threading ...
		run threaded_second_pass() in the main process
	}
It could (and should) be like this instead from the beginning, I think:
	parse_pack_objects()
	{
		... a lot of code for the first pass ...
		second_pass()
	}

to encapsulate the whole second_pass() logic in the refactored function, whose implementation (i.e. how the objects to be processed are picked up and worked on) will change in the threaded version. In the first refactoring patch, second_pass() would still iterate over object entries:

	second_pass()
	{
		for (all object entries) {
			resolve_deltas(base_obj)
		}
	}

And at this point, introduce a helper function "resolve_deltas(base)" or something that is your "second_pass()". This deals with only one family of objects that use the given object as their (recursive) base objects, and use it in the above loop.

And then multi-threading support can turn that into something like
	second_pass()
	{
	#if WE SUPPORT THREADING
		for (number of threads we are going to spawn) {
			spawn thread and let it run threaded_second_pass
		}
		for (all threads) {
			cull them when they are done
		}
		return
	#endif
		... when not threading ...
		for (all object entries) {
			resolve_deltas(base_obj)
		}
	}

to add support for threaded case. The threaded_second_pass function does only one thing and one thing well:

	threaded_second_pass()
	{
		set thread local
		loop forever {
			take work item under critical section
			break if there is no more work
			resolve_deltas(the work item)
		}
	}
Wouldn't the result be much more readable that way?

You may have saved a few lines by making unthreaded code call your threaded_second_pass() and pretend that the single main process still has to pick up a work item and work on it in a loop like you did, but I think it made the logic unnecessarily harder to follow.

Previous: Nguyen Thai Ngoc DuyNext: Nguyễn Thái Ngọc Duy
Message 8 of 13 in “Multithread index-pack”
  1. 0/3 Multithread index-packNguyễn Thái Ngọc Duy, Apr 11, 2012
  2. 1/3 compat/win32/pthread.h: Add an pthread_key_delete() implementationNguyễn Thái Ngọc Duy, Apr 11, 2012
  3. 2/3 index-pack: split second pass obj handling into own functionNguyễn Thái Ngọc Duy, Apr 11, 2012
  4. 3/3 index-pack: support multithreaded delta resolvingNguyễn Thái Ngọc Duy, Apr 11, 2012
  5. Junio C HamanoMay 3, 2012
  6. Junio C HamanoMay 4, 2012
  7. Nguyen Thai Ngoc DuyMay 4, 2012
  8. Junio C HamanoMay 4, 2012
  9. 1/4 compat/win32/pthread.h: Add an pthread_key_delete() implementationNguyễn Thái Ngọc Duy, May 6, 2012
  10. 2/4 index-pack: restructure pack processing into three main functionsNguyễn Thái Ngọc Duy, May 6, 2012
  11. Junio C HamanoMay 8, 2012
  12. 3/4 index-pack: support multithreaded delta resolvingNguyễn Thái Ngọc Duy, May 6, 2012
  13. 4/4 index-pack: disable threading if NO_PREAD is definedNguyễn Thái Ngọc Duy, May 6, 2012

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.