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

Re: [PATCH V2 3/3] strbuf: allow to use preallocated memory

From
Jeff King <peff@peff.net>
Date
Jun 8, 2016, 19:52 UTC
Message-ID
<20160608195248.GA4264@sigill.intra.peff.net>
In-Reply-To
<xmqq37onlawb.fsf@gitster.mtv.corp.google.com>
On Wed, Jun 08, 2016 at 12:48:36PM -0700, Junio C Hamano wrote:
Show 17 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > That made me wonder if we could repeatedly reuse a buffer attached to
> > the file descriptor. And indeed, isn't that what stdio is? The whole
> > reason this buffer exists is because we are using a direct descriptor
> > write. If we switched this function to use fprintf(), we'd avoid the
> > whole buffer question, have a fixed cap on our memory use (since we just
> > flush anytime the buffer is full) _and_ we'd reduce the number of
> > write syscalls we're making by almost a factor of 100.
> 
> The primary reason why we avoid stdio in the lower level part of I/O
> is that the error reporting and handling is horrible.
> 
> e.g. c.f. http://article.gmane.org/gmane.comp.version-control.git/27019
> 
> Otherwise, I'd agree with your "Why aren't we using stdio if
> counting and avoiding overflow is so hard?".

I agree it can be confusing (especially on the output side your errors are likely deferred until the next flush). But in this particular case, I think it's an improvement (see the patch I just sent and its discussion of error handling).

I also think we could smooth over the rough edges by wrapping the complexity (we already have fprintf_or_die, which arguably could be used in this case, but I went with the solution that stayed closer to what the original code was doing). And if stdio is truly too horrible, I'd suggest we implement our own buffered I/O. Because that's effectively what such call-sites are doing, but in a really ad-hoc and non-performant way.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 31 of 32 in “strbuf: improve API”
  1. 0/3 strbuf: improve APIWilliam Duclot, Jun 6, 2016
  2. 1/3 strbuf: add testsWilliam Duclot, Jun 6, 2016
  3. Matthieu MoyJun 6, 2016
  4. Johannes SchindelinJun 7, 2016
  5. 2/3 pretty.c: rename strbuf_wrap() functionWilliam Duclot, Jun 6, 2016
  6. Matthieu MoyJun 6, 2016
  7. Johannes SchindelinJun 7, 2016
  8. 3/3 strbuf: allow to use preallocated memoryWilliam Duclot, Jun 6, 2016
  9. Matthieu MoyJun 6, 2016
  10. Junio C HamanoJun 6, 2016
  11. William DuclotJun 6, 2016
  12. Junio C HamanoJun 6, 2016
  13. Jeff KingJun 6, 2016
  14. Junio C HamanoJun 6, 2016
  15. Junio C HamanoJun 6, 2016
  16. Jeff KingJun 6, 2016
  17. William DuclotJun 7, 2016
  18. Junio C HamanoJun 7, 2016
  19. Michael HaggertyJun 8, 2016
  20. Junio C HamanoJun 8, 2016
  21. Jeff KingJun 8, 2016
  22. send-pack: use buffered I/O to talk to pack-objectsJeff King, Jun 8, 2016
  23. Matthieu MoyJun 9, 2016
  24. Ramsay JonesJun 9, 2016
  25. Jeff KingJun 9, 2016
  26. Ramsay JonesJun 9, 2016
  27. Junio C HamanoJun 9, 2016
  28. Jeff KingJun 9, 2016
  29. Matthieu MoyJun 9, 2016
  30. Junio C HamanoJun 8, 2016
  31. Jeff KingJun 8, 2016
  32. Junio C HamanoJun 8, 2016

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.