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

Re: [PATCH] csum-file: flush less often

From
Jeff King <peff@peff.net>
Date
Mar 26, 2021, 03:16 UTC
Message-ID
<YF1SJRhb8hz7NP0/@coredump.intra.peff.net>
In-Reply-To
<xmqq4kgzvzf6.fsf@gitster.g>
On Thu, Mar 25, 2021 at 11:52:29AM -0700, Junio C Hamano wrote:
Show 18 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> 
> >> So, I'm of two minds here:
> >>
> >>  1. This is embarassing. I wasted everyone's time for nothing. I can retract
> >>     this patch.
> >>
> >>  2. This is embarassing. I overstated the problem here. But we might be able
> >>     to eke out a tiny performance boost here.
> >>
> >> I'm open to either. I think we should default to dropping this patch unless
> >> someone thinks the rewrite above is a better organization of the logic. (I
> >> can then send a v2 including that version and an updated commit message.)
> >
> > 3. The current code around "if (nr == sizeof(f->buffer))" might be a
> >    bit too clever for readers who try to understand what is going
> >    on, and the whole "while" loop may deserve a comment based on
> >    what you wrote before your replacement implementation.

Yes, my first thought on reading Stolee's post-image was: wait, how do we know when data needed flushed from the buffer? But that is not new in his patch. It is confusing before and after. :)

Show 7 quoted lines
> Having said all that, comparing the original and the version updated
> with your "flush less often" patch, I find the latter quite easier
> to read, so as long as the update does not give us 1% slowdown, it
> may be worth adopting for the readability improvement alone.
> 
> Of course, if we were to go that route, the sales pitch in the log
> message needs to be updated.

Yeah, I am OK with either version, as long as it is justified correctly in the commit message. IMHO the big difference is that the original is using local data/offset variables in order to provide a layer of indirection when we get to the hash+flush code. And Stolee's patch is calling the same code in the two places instead.

It's quite possible that gives the compiler slightly more opportunity to micro-optimize (which doesn't matter if you are feeding big blocks, but may if you are feeding 4 bytes at a time as in the midx code; though in that case it is entirely possible that the caller allocating a single array, writing it, and then feeding it to hashwrite() would be faster still, though a little more cumbersome).

-Peff
Previous: Junio C HamanoNext: Derrick Stolee via GitGitGadget
Message 5 of 8 in “csum-file: flush less often”
  1. csum-file: flush less oftenDerrick Stolee via GitGitGadget, Mar 24, 2021
  2. Derrick StoleeMar 25, 2021
  3. Junio C HamanoMar 25, 2021
  4. Junio C HamanoMar 25, 2021
  5. Jeff KingMar 26, 2021
  6. csum-file: make hashwrite() more readableDerrick Stolee via GitGitGadget, Mar 26, 2021
  7. Junio C HamanoMar 26, 2021
  8. Jeff KingMar 28, 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.