-
-
Notifications
You must be signed in to change notification settings - Fork 227
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
Replace all uses of format!() #23
Conversation
ce909cc
to
4ae0bf5
Compare
Thank you very much for your contribution! I'm not too happy with this solution. If we go with this, I think we should generate this lookup table somehow instead of having this huge array in the source code. Couldn't we apply the same method as you did in #24 and replace the |
We could use a single |
Here's the difference I see:
Another benefit of using a lookup table is we could stuff the ANSI color escapes in there as well (though in this case we'd definitely want to generate it at runtime), which would avoid having to categorize each byte in order to color it and avoid having to synthesize ANSI escapes for each byte. |
That is true, yes. That could be a more significant speedup. In this case, I'd like to structure the lookup-table login into a new file and struct. |
Wow, getting rid of the ANSI escape calculation per byte is a huge win:
I'll push that momentarily. |
f9d9aaa
to
3c9ae4f
Compare
Awesome! Thank you very much. This looks clean enough to leave it in the main file. And we can still refactor later.. |
How much do we gain by using |
If we apply the same trick to the char version we get even faster:
I'll test the non-unsafe version in a minute. |
3c9ae4f
to
ceaabb2
Compare
The |
Previously we were allocating 2 strings per byte, plus another for the offset. Instead we can just write all this directly to stdout. Also replace the calculation of the ANSI escape code for every single byte. This produces a significant speedup.
ceaabb2
to
3d17daa
Compare
Fantastic, thank you very much for these real time updates! 😄 I'd like to get this merged so I can include it in v0.3.1, which I'd like to release now. Happy to work on even more improvements in other PRs. |
Sounds good to me. I need to go to bed anyway. |
We're faster than
|
Replace all uses of format!()
Previously we were allocating 2 strings per byte, plus another for the offset. Instead we can just write all this directly to stdout.
Also replace the calculation of the ANSI escape code for every single byte. This produces a significant speedup.
I tested this by ensuring the output of dumping a 1.3MB file (the hexyl binary itself) was byte-for-byte identical to without this PR.
Benchmark output: