-
Notifications
You must be signed in to change notification settings - Fork 139
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
add conditional formatting for Terminal #651
Conversation
Performance is absolutely critical here because |
Having said that, adding a single branch (which should be predicted correctly ~100% of the time) and one function call per So, concept ACK reducing performance in this way. But I'm a little torn about how much uglier/harder to maintain this makes the code. |
It is uglier, but in a way is more maintainable, since there aren't 2 different places to update. |
Let's implement and see how much it impacts the code size |
Sounds good. FYI at least one of the CI failures is real -- you need to run the formatter. |
7ad6d5c
to
f6c8798
Compare
I used the total given by this call to benchmark master | 354.4KiB Note that much of the total filtered space is from unrelated fn ( Note that I tryed to be equivalent to master but I don't know why there is difference in Debug and Display in where there is the call to cargo bloat after 2nd commit
|
fmt functions produce big binaries. Since Debug and Display implementation of the match are equal except the Debug or Display representation of its child, this introduce conditional fmt trading performance for code size. The branch introduced should be easily predicted so the performance impact shouldn't be big.
f6c8798
to
d00e49b
Compare
@RCasatta the reason is that in I think it's fine to unify them so they both act like |
by refactoring out the function when the type is known, we avoid the duplication in the generic function. In the process write_char is replaced with write_str when the string is static because by looking at the impl it saves a utf8 str conversion from the char.
d00e49b
to
395aab8
Compare
Added a commit for this, updated failing test to the different Debug impl. There is less information printed out not sure it is desired. Latest binary sizes didn't consider rebase on master, updated one are the following: |
Cool, let's bring this in! I have another idea to introduce an Another idea is to pull the wrapper-formatting logic out of the generic format. Though that maybe depends on Anyway this is an improvement and it's not API-visible so it's fine to have some churn here. So let's merge it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 395aab8
Probably similar to the |
…s and multi/multi_a 200991d compiler: improve logic for deciding between thresholds and ands (Andrew Poelstra) bc3b8dc policy: rename Threshold variant to Thresh (Andrew Poelstra) 78db616 consolidate some FIXMEs (Andrew Poelstra) 0666aef error: remove some unused variants (Andrew Poelstra) b2ec4a8 clippy: fix some nits introduced by #651 (Andrew Poelstra) Pull request description: The compiler logic when encountering thresholds of pks is currently a bit confused, and therefore chooses multi/multi_a in cases where this is not the most efficient compilation. This PR fixes that, and also brings in a few other cleanup commits that I had laying around. This does **not** fix #656, which I didn't know how to approach. ACKs for top commit: sanket1729: ACK 200991d Tree-SHA512: 252a60891cf1c1d1cd3ded88d97122fd1e76bd25807770f4843ae68bd2d854fc617518f26be86dcb57cd7fc369e1a4be81daa42ee1a6d4bc976dbad6dc1150f6
fmt functions produce big binaries.
cargo bloat --release --example big --all-features -n 1000000 --full-fn | grep astelem | grep fmt
0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::h75ba3ce6da61d374 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::h6786aa26184b9ff6 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::h03f9c2155559a440 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::h00e63af9b88389b4 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::hb60190c99fd48d17 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::ha9001c527b4cc4d6 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::ha726829fe4f3bf2b 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::h95a7eadaa261d645 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::h819e09dcb99bbc52 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::h6ef89d30f9f4cb57 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::h693edb5e35f9fc08 0.0% 0.1% 2.8KiB miniscript miniscript::miniscript::astelem::>::fmt::h27891ccf9609c782 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::he0a63893fe76f527 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h86eba44cb7298c4f 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h37a4628264df8c3b 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h2f3a9d297ec35dea 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h879ad74922a70f16 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h7dc2d9bc27c88fab 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h7578352fd420fc88 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h1809b9931776159e 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::hf7760e0f27d70db4 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h9adfe0d7e2bfdd42 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h61cdb06e2a061932 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h44e1ab5daacde0df 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h2646ddd57694241b 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::he31fd2e9b12960f9 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::hbefb77c4050bd5c9 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::hb4deb7ef951af7af 0.0% 0.1% 2.7KiB miniscript miniscript::miniscript::astelem::>::fmt::h80ee1108b955f2b4 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::hc779f37cb81f761a 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::hc4ac4a9b598fbdfb 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h5cca31d73f30c3c7 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h4588410e445d16c6 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::heb60f683c9e55e36 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::hbe7939a797fcce35 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::ha536af3ff4313ed1 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h8969ddab726dea7f 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h7fca0d80a428dd24 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h6b4909db760a4721 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h5ed643a399966d49 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h1ed7d512c859a5a9 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::hfd9775e798913648 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::hf87563509ea7253d 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::hb8b75c9c988d95c3 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h87b650968eb119ba 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h9986ae4314d85479 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h74343d637646e38a 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h680da8fa0ec0142c 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h6197658ba03f1fdf 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h961e1a4b75732a11 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h57b3cd148371177a 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h13d43f019a96d314 0.0% 0.1% 2.6KiB miniscript miniscript::miniscript::astelem::>::fmt::h008ca416c1ebc0d7 0.0% 0.1% 2.5KiB miniscript miniscript::miniscript::astelem::>::fmt::h82a27926db80dc37 0.0% 0.1% 2.5KiB miniscript miniscript::miniscript::astelem::>::fmt::hc12b3098c3979175 0.0% 0.1% 2.5KiB miniscript miniscript::miniscript::astelem::>::fmt::h76e624d7abc545ba 0.0% 0.1% 2.5KiB miniscript miniscript::miniscript::astelem::>::fmt::h24511846d004e114 0.0% 0.1% 2.5KiB miniscript miniscript::miniscript::astelem::>::fmt::h0d96e9d943f04d7dSince Debug and Display implementations are ~equal except the Debug or Display representation of its child, this introduce conditional fmt trading performance for code size. Since performance shouldn't be that important in string conversion seems an interesting trade-off.
This is a PoC since the final impl of
conditional_fmt
is a little tedious, would like a concept ack before proceding