sharkdp / hexyl

A command-line hex viewer
Apache License 2.0
8.92k stars 227 forks source link

`hexyl /dev/zero` hangs #200

Closed GrigorenkoPV closed 6 months ago

GrigorenkoPV commented 10 months ago

So does

hexyl < /dev/zero

or

cat /dev/zero | hexyl

I guess it has to do with hexyl's feature where it skips null rows and prints only the first and the last.

sharifhsn commented 10 months ago

What do you expect the behavior to be in this instance?

GrigorenkoPV commented 10 months ago

What do you expect the behavior to be in this instance?

Anything but empty output, which makes it impossible to tell if anything is happening at all.

  1. Spitting out a bunch of zeroes as xxd does. But I guess it goes against the design of hexyl.
  2. The zeroes before the skipped part. Let me explain.
    dd if=/dev/zero count=5000B | hexyl

    outputs

    ┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
    │00000000│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
    │*       │                         ┊                         │        ┊        │
    │00001380│ 00 00 00 00 00 00 00 00 ┊                         │⋄⋄⋄⋄⋄⋄⋄⋄┊        │
    └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

    so it would be cool if

    hexyl /dev/zero

    printed

    ┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
    │00000000│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
    │*       │                         ┊                         │        ┊        │

    and then hanged. So yeah, basically just flushing the output after the * row.

sharkdp commented 10 months ago

So yeah, basically just flushing the output after the * row.

Agreed. This is also what hexdump -C and xxd -a (-a = autoskip = squeezing) do.

Thank you for reporting this.

sharifhsn commented 10 months ago

Great, I'll look into fixing this today.

sharifhsn commented 10 months ago

It looks like the issue is a simple one-liner: the write buffer isn't flushed until the very end of output. I wrote it this way initially to mitigate performance issues from flushing the buffer, but benchmarks show that the effect is negligible. I've added a line that will flush after every line.

sharkdp commented 9 months ago

It looks like the issue is a simple one-liner: the write buffer isn't flushed until the very end of output. I wrote it this way initially to mitigate performance issues from flushing the buffer, but benchmarks show that the effect is negligible. I've added a line that will flush after every line.

Thank you very much for looking into this! Any chance you could share those benchmark results? I also would have expected repeated flush calls for every line to be performance-relevant.