Re: [PATCH 02/20] scripts/make-erofs.sh: Do not read one byte at a time

Demi Marie Obenour
2025-09-08T16:57:32Z

[-- Attachment #1.1.1: Type: text/plain, Size: 797 bytes --]

On 9/8/25 04:23, Alyssa Ross wrote:
> Demi Marie Obenour <demiobenour@gmail.com> writes:
>
>> POSIX requires that the shell read builtin not consume any bytes beyond
>> the end-of-line character. For non-seekable files like pipes, this
>> requirement can only be met by reading one byte at a time, which is very
>> slow. Avoid this by reading the entire input into a temporary file and
>> having sh read from the temporary file. Since regular files are
>> seekable, sh can read many bytes and then seek back to the correct file
>> position.
>
> Slow enough to make a noticeable difference in the context of the whole
> script?

Don't know 🙂. It's just a known antipattern and
I saw bash using a decent amount of CPU time.
--
Sincerely,
Demi Marie Obenour (she/her/hers)

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]