* [PATCH] strbuf_write: omit system call when length is zero
@ 2016-02-25 22:34 Stefan Beller
2016-02-25 23:04 ` Junio C Hamano
2016-02-26 0:47 ` Duy Nguyen
0 siblings, 2 replies; 5+ messages in thread
From: Stefan Beller @ 2016-02-25 22:34 UTC (permalink / raw)
To: gitster; +Cc: git, Jens.Lehmann, peff, sunshine, jrnieder, Stefan Beller
In case the length of the buffer is zero, we do not need to call the
fwrite system call as a performance improvement.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
This applies on top of v17 for origin/sb/submodule-parallel-update.
In case there are other reasons for origin/sb/submodule-parallel-update
to need a reroll I'll squash it in. But as this is a pure performance
optimization in a case we are not running into with that series and that
series is clashing with Davids refs backend series, I figure we may not
want to have a reroll for this fix alone.
Thanks,
Stefan
strbuf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/strbuf.c b/strbuf.c
index 71345cd..5f6da82 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -397,7 +397,7 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
ssize_t strbuf_write(struct strbuf *sb, FILE *f)
{
- return fwrite(sb->buf, 1, sb->len, f);
+ return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;
}
--
2.7.2.374.ga5f0819.dirty
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] strbuf_write: omit system call when length is zero
2016-02-25 22:34 [PATCH] strbuf_write: omit system call when length is zero Stefan Beller
@ 2016-02-25 23:04 ` Junio C Hamano
2016-02-26 0:47 ` Duy Nguyen
1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2016-02-25 23:04 UTC (permalink / raw)
To: Stefan Beller; +Cc: git, Jens.Lehmann, peff, sunshine, jrnieder
Stefan Beller <sbeller@google.com> writes:
> In case the length of the buffer is zero, we do not need to call the
> fwrite system call as a performance improvement.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> This applies on top of v17 for origin/sb/submodule-parallel-update.
>
> In case there are other reasons for origin/sb/submodule-parallel-update
> to need a reroll I'll squash it in. But as this is a pure performance
> optimization in a case we are not running into with that series and that
> series is clashing with Davids refs backend series, I figure we may not
> want to have a reroll for this fix alone.
Yeah, I tend to agree that this change by itself is probably not
worth much.
While I agree with the idea of passing the output from children thru
with as little modification as possible, I think that goal does not
have to be incompatible with the idea you and Jonathan had to ensure
that the output is safe in the presence of incomplete last line.
I think the output made from pp_collect_finished() for "other
finished processes" is known to have the very last part from
finished child, so it would be easy to make sure by calling
strbuf_complete_line() that pp->children[i].err is terminated.
I haven't thought it through how the output from CP_WORKING process
in pp_output() should be kept track of, though.
It might be just a matter of adding a bit "incomplete_last_line" to
the parallel_process.children struct and maintain it every time
pp_output() writes something out (we cannot add an extra newline in
pp_output() because we don't know if the process will have further
output, but we can keep track of the fact that the last output did
not have the final newline). In pp_collect_finished(), we can use
the bit and the contents of pp->children[i].err to decide if we need
to call strbuf_complete_line() if we did so.
Or something like that ;-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] strbuf_write: omit system call when length is zero
2016-02-25 22:34 [PATCH] strbuf_write: omit system call when length is zero Stefan Beller
2016-02-25 23:04 ` Junio C Hamano
@ 2016-02-26 0:47 ` Duy Nguyen
2016-02-26 1:40 ` Junio C Hamano
1 sibling, 1 reply; 5+ messages in thread
From: Duy Nguyen @ 2016-02-26 0:47 UTC (permalink / raw)
To: Stefan Beller
Cc: Junio C Hamano, Git Mailing List, Jens Lehmann, Jeff King,
Eric Sunshine, Jonathan Nieder
On Fri, Feb 26, 2016 at 5:34 AM, Stefan Beller <sbeller@google.com> wrote:
> In case the length of the buffer is zero, we do not need to call the
> fwrite system call as a performance improvement.
fwrite is a libc call, not system call. Are you sure it always calls
write() (assuming buffering is off)?
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> This applies on top of v17 for origin/sb/submodule-parallel-update.
>
> In case there are other reasons for origin/sb/submodule-parallel-update
> to need a reroll I'll squash it in. But as this is a pure performance
> optimization in a case we are not running into with that series and that
> series is clashing with Davids refs backend series, I figure we may not
> want to have a reroll for this fix alone.
>
> Thanks,
> Stefan
>
>
> strbuf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/strbuf.c b/strbuf.c
> index 71345cd..5f6da82 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -397,7 +397,7 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
>
> ssize_t strbuf_write(struct strbuf *sb, FILE *f)
> {
> - return fwrite(sb->buf, 1, sb->len, f);
> + return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;
> }
>
>
> --
> 2.7.2.374.ga5f0819.dirty
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Duy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] strbuf_write: omit system call when length is zero
2016-02-26 0:47 ` Duy Nguyen
@ 2016-02-26 1:40 ` Junio C Hamano
2016-02-26 17:09 ` Stefan Beller
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2016-02-26 1:40 UTC (permalink / raw)
To: Duy Nguyen
Cc: Stefan Beller, Git Mailing List, Jens Lehmann, Jeff King,
Eric Sunshine, Jonathan Nieder
Duy Nguyen <pclouds@gmail.com> writes:
> On Fri, Feb 26, 2016 at 5:34 AM, Stefan Beller <sbeller@google.com> wrote:
>> In case the length of the buffer is zero, we do not need to call the
>> fwrite system call as a performance improvement.
>
> fwrite is a libc call, not system call. Are you sure it always calls
> write() (assuming buffering is off)?
I do not think so, but I suspect that the patch misstates its
rationale (I said I get uncomfortable every time I see a function
that takes size and nelem separately used by a caller that can
potentially pass nleme=0, when I wondered it it is OK that no caller
of this funtion checks its return value).
>
>>
>> Signed-off-by: Stefan Beller <sbeller@google.com>
>> ---
>>
>> This applies on top of v17 for origin/sb/submodule-parallel-update.
>>
>> In case there are other reasons for origin/sb/submodule-parallel-update
>> to need a reroll I'll squash it in. But as this is a pure performance
>> optimization in a case we are not running into with that series and that
>> series is clashing with Davids refs backend series, I figure we may not
>> want to have a reroll for this fix alone.
>>
>> Thanks,
>> Stefan
>>
>>
>> strbuf.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/strbuf.c b/strbuf.c
>> index 71345cd..5f6da82 100644
>> --- a/strbuf.c
>> +++ b/strbuf.c
>> @@ -397,7 +397,7 @@ ssize_t strbuf_read_once(struct strbuf *sb, int fd, size_t hint)
>>
>> ssize_t strbuf_write(struct strbuf *sb, FILE *f)
>> {
>> - return fwrite(sb->buf, 1, sb->len, f);
>> + return sb->len ? fwrite(sb->buf, 1, sb->len, f) : 0;
>> }
>>
>>
>> --
>> 2.7.2.374.ga5f0819.dirty
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe git" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] strbuf_write: omit system call when length is zero
2016-02-26 1:40 ` Junio C Hamano
@ 2016-02-26 17:09 ` Stefan Beller
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Beller @ 2016-02-26 17:09 UTC (permalink / raw)
To: Junio C Hamano
Cc: Duy Nguyen, Git Mailing List, Jens Lehmann, Jeff King,
Eric Sunshine, Jonathan Nieder
On Thu, Feb 25, 2016 at 5:40 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Duy Nguyen <pclouds@gmail.com> writes:
>
>> On Fri, Feb 26, 2016 at 5:34 AM, Stefan Beller <sbeller@google.com> wrote:
>>> In case the length of the buffer is zero, we do not need to call the
>>> fwrite system call as a performance improvement.
>>
>> fwrite is a libc call, not system call. Are you sure it always calls
>> write() (assuming buffering is off)?
>
> I do not think so, but I suspect that the patch misstates its
> rationale (I said I get uncomfortable every time I see a function
> that takes size and nelem separately used by a caller that can
> potentially pass nleme=0, when I wondered it it is OK that no caller
> of this funtion checks its return value).
>
This is exactly what happened. I assumed fwrite would be a system call
eventually.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-02-26 17:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-25 22:34 [PATCH] strbuf_write: omit system call when length is zero Stefan Beller
2016-02-25 23:04 ` Junio C Hamano
2016-02-26 0:47 ` Duy Nguyen
2016-02-26 1:40 ` Junio C Hamano
2016-02-26 17:09 ` Stefan Beller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).