Skip to content

OnFinalCount iterator adapter - #5985

Merged
JojiiOfficial merged 1 commit into
devfrom
on_final_count-iter
Mar 6, 2025
Merged

JojiiOfficial merged 1 commit into
devfrom
on_final_count-iter

Conversation

@coszio

@coszio coszio commented Feb 13, 2025

Copy link
Copy Markdown
Contributor

This PR adds an iterator adapter to make hardware usage counting easier when we are measuring iterators.

This adapter plugs in easily to an iterator. When the iterator gets dropped, it will execute the callback to do something with the final number of iterations the iterator was used for.

For example:

index.value_to_points.get_iter(value).on_final_count(|nexts| {
    hw_counter
        .payload_index_io_read_counter()
        .incr_delta(nexts * size_of::<PointOffsetType>)
});

I am not sure about the name, though. Feel free to propose another one :)

@JojiiOfficial JojiiOfficial left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a nice addition. Thanks!

/// including the final one where it usually returns `None`.
///
/// Consider subtracting 1 if the final `None` is not needed.
fn on_final_count<F>(self, f: F) -> OnFinalCount<Self, F>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A bit verbose, but how about count_callback_on_drop? It might give a better hint on what it does without looking at the function.

I've no strong opinion on either.

cc @JojiiOfficial

@JojiiOfficial JojiiOfficial Mar 5, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm fine with both but agree this one being more self-explanatory

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.

3 participants