Skip to content

initial draft oft hold_max with heuristic#657

Merged
djc merged 2 commits intoconsole-rs:mainfrom
djugei:heuristic
Nov 16, 2025
Merged

initial draft oft hold_max with heuristic#657
djc merged 2 commits intoconsole-rs:mainfrom
djugei:heuristic

Conversation

@djugei
Copy link
Contributor

@djugei djugei commented Sep 9, 2024

alternative or update to #642

In BufRead/AsyncBufRead fill_buf does not logically consume the reader/advance progress, only a call to consume does. this was the wrong way around for the AsyncBufRead implementation, i have fixed that in this pr.

@djugei
Copy link
Contributor Author

djugei commented Sep 13, 2024

this is now ready for some feedback @djc

@djugei
Copy link
Contributor Author

djugei commented Oct 11, 2024

would love some feedback on this

@djugei djugei force-pushed the heuristic branch 5 times, most recently from e72c3c9 to d0715e4 Compare February 5, 2025 20:25
@djugei
Copy link
Contributor Author

djugei commented Jul 6, 2025

can i get some feedback on this?

@djugei
Copy link
Contributor Author

djugei commented Jul 6, 2025

rebased to 1.18

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the very long delay -- here's some initial feedback. Needs a bunch of work.

Please squash all of your commits and avoid making changes to the existing structure of the code as much as possible (or isolate such changes in separate commits).

@djugei
Copy link
Contributor Author

djugei commented Jul 10, 2025

Please squash all of your commits

will do before a merge, i am keeping it in separate commits for now to make reviews easier (for example its somewhat easier to ignore the code movements by just not looking at that commit etc)

i will make the requested changes over the weekend probably

@djugei djugei force-pushed the heuristic branch 3 times, most recently from b408abb to 23a4b1d Compare July 13, 2025 07:40
@djugei
Copy link
Contributor Author

djugei commented Jul 13, 2025

I have done all(-1) of the requested changes, also split out the bug fix into a separate commit while squashing all other changes.

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, and sorry for the very slow feedback -- will try to be faster for the next one.

One more nit: you have a bunch of unidiomatic variable names, oldpos, maxpos. All of these should have underscores (like old_pos). Also suggest prev_ instead of old_ prefixes.

src/iter.rs Outdated
Comment on lines +306 to +307
// % here is a purely for the optimizer
let head: usize = usize::from(self.head) % self.vals.len();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop the unnecessary type annotation. Unless you've seen actual benchmark data where the % matters, let's drop the optimization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have decided doubling down on this, i am altering the docs/comments to talk more about invariants.

i have just rechecked, it does fully eliminate bounds checks. while bounds checks are not that performance intensive, it also eliminates the entire panic path, which has a positive impact on code size. Also it just feels right to feed the compiler additional information.

i was somewhat tempted to use std::hint::assert_unchecked, which has much the same effect, but also eliminates the modulo calculations. i opted to not introduce unsafe code, though its correctness can be somewhat trivially asserted.

@djugei djugei force-pushed the heuristic branch 2 times, most recently from 66002de to c7886d7 Compare October 16, 2025 10:58
@djugei
Copy link
Contributor Author

djugei commented Oct 16, 2025

integrated feedback

@djugei djugei requested a review from djc October 16, 2025 11:03
@djugei
Copy link
Contributor Author

djugei commented Oct 16, 2025

Thanks for working on this, and sorry for the very slow feedback -- will try to be faster for the next one.

no worries, we all do this in our free time, and the interactions with this project have been plesant so far, much worse is possible :D

off topic but also thanks for cutting the dialoguer release that outdated dependency has been bugging me for quite a while now, i try to only ever have one version of a lib in my dependency tree.

@djugei
Copy link
Contributor Author

djugei commented Nov 14, 2025

sorry for the wait, have resolved the issues.

i have also rebased to latest master.

@djc
Copy link
Member

djc commented Nov 14, 2025

Thanks -- can you fix up the clippy issue? I will do a pass after this is merged to clean up some things.

@djugei
Copy link
Contributor Author

djugei commented Nov 16, 2025

the clippy issue is literally a change you requested, but i have fixed it now.

On the first seek it gets enabled, displaying the progress as the max
of the last 10 updates.
If there ever are more than 5 consecutive reads and writes without seek
it gets disabled again, keeping the performance impact low.
@djc djc merged commit 2f2b2cc into console-rs:main Nov 16, 2025
11 checks passed
@djc djc mentioned this pull request Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants