Subject: bug#46881: 28.0.50; pdumper dumping causes way too many syscalls

From: Daniel Colascione <[email-masked]>
Date: Fri, 5 Mar 2021 09:13:49 -0500

On 3/5/21 9:02 AM, Pip Cet wrote:

> On Fri, Mar 5, 2021 at 1:16 PM Pip Cet <[email-masked]> wrote:
>>> I say let's go with stdio.
>> Maybe setbuffer(3) could help us here? I could run some benchmarks for
>> that if the idea isn't out of the question.
> Actually, calling setbuffer() with a large buffer will make glibc
> reread the entire file on every fseek(), rendering the dump so slow I
> gave up and interrupted it.
>
> However, there's open_memstream: that would have the added advantage
> of actually making glibc write out the entire file in one go, so it
> seems to shave a few extra milliseconds off the build.
>
> (However however, glibc's memstreams are somewhat broken. I'll file a
> bug report if there isn't one already...)
>
> Still, that way we could use stdio today, leave the buffering to
> glibc, and hopefully be able to switch trivially to a "open this file
> but keep it in memory" combined memstream/FILE* one day.

You could also use fopencookie to make your own stdio stream that does 
the right thing while still using the stdio abstraction in the part of 
the code actually doing the writing.