Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hexyl /dev/zero hangs #200

Closed
GrigorenkoPV opened this issue Aug 15, 2023 · 6 comments · Fixed by sharifhsn/hexyl#2 or #211
Closed

hexyl /dev/zero hangs #200

GrigorenkoPV opened this issue Aug 15, 2023 · 6 comments · Fixed by sharifhsn/hexyl#2 or #211

Comments

@GrigorenkoPV
Copy link
Contributor

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
Copy link
Contributor

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

@GrigorenkoPV
Copy link
Contributor Author

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
Copy link
Owner

sharkdp commented Aug 21, 2023

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
Copy link
Contributor

Great, I'll look into fixing this today.

@sharifhsn
Copy link
Contributor

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.

sharifhsn added a commit to sharifhsn/hexyl that referenced this issue Aug 21, 2023
@sharkdp
Copy link
Owner

sharkdp commented Sep 16, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants