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
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
May 4, 2012, 12:50 UTC
Message-ID
<CACsJy8DHtBZdhoh1BPwn2_-3wVDRWypJOg3kR9wjd2o1bLUW-Q@mail.gmail.com>
In-Reply-To
<7vipgccvp9.fsf@alter.siamese.dyndns.org>

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.

On Fri, May 4, 2012 at 1:21 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 69 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
>>
>>> @@ -696,7 +796,31 @@ static void second_pass(struct object_entry *obj)
>>>      base_obj->obj = obj;
>>>      base_obj->data = NULL;
>>>      find_unresolved_deltas(base_obj);
>>> -    display_progress(progress, nr_resolved_deltas);
>>> +}
>>> +
>>> +static void *threaded_second_pass(void *arg)
>>> +{
>>> +#ifndef NO_PTHREADS
>>> +    if (threads_active)
>>> +            pthread_setspecific(key, arg);
>>> +#endif
>>> +    for (;;) {
>>> +            int i;
>>> +            work_lock();
>>> +            display_progress(progress, nr_resolved_deltas);
>>> +            while (nr_processed < nr_objects &&
>>> +                   is_delta_type(objects[nr_processed].type))
>>> +                    nr_processed++;
>>> +            if (nr_processed >= nr_objects) {
>>> +                    work_unlock();
>>> +                    break;
>>> +            }
>>> +            i = nr_processed++;
>>> +            work_unlock();
>>> +
>>> +            second_pass(&objects[i]);
>>> +    }
>>> +    return NULL;
>>>  }
>>
>> It may be just the matter of naming, but the above is taking the
>> abstraction backwards, I think.  Shouldn't it be structured in such a way
>> that the caller may call second_pass() and its implementation may turn out
>> to be threaded (or not)?
>>
>> The naming of "arg" made things worse.  I wasted 5 minutes scratching my
>> head thinking "arg" was a single specific object that was to be given to
>> second_pass(), and wondered why it is made into thread-local data.  Name
>> it "thread_data" or something.
>>
>> And I think the root cause of this confusion is the way "second_pass" was
>> split out in the earlier patch.  It is not the entire second-pass, but is
>> merely a single step of it (the whole "for (i = 0; i < nr_objects; i++)"
>> is the second-pass, in other words), and its implementation detail might
>> change to either thread (i.e. instead of a single line of control
>> iterating from 0 to nr_objects, each thread grab the next available task
>> and work on it until everything is exhausted) or not.
>>
>> By the way, if one object is very heavy and takes a lot of time until
>> completion, could it be possible that objects[0] is still being processed
>> for its base data but objects[1] has already completed and an available
>> thread could work on objects[2]?  How does it learn to process objects[2]
>> in such a case, or does it wait until the thread working on objects[0] is
>> done?
>
> Please disregard the "By the way" part, except that my confusion that led
> to the "By the way" comment was caused by another misnaming, namely,
> "nr_processed".  It is not counting "How many of them have we already
> processed?"---it merely counts "How many of them have we dispatched?" and
> completion of the task does not matter in this critical section, which I
> missed.  If it were named "nr_dispatched", I wouldn't have wasted my time
> wondering about the loop and writing the "By the way" review comment.
>
-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 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.