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

Driver::register() takes too many arguments #5985

Merged
merged 4 commits into from
Jul 1, 2024
Merged

Conversation

davepacheco
Copy link
Collaborator

Following up from #5962 (comment)

@davepacheco davepacheco requested a review from hawkw July 1, 2024 18:38
@davepacheco davepacheco self-assigned this Jul 1, 2024
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

Looks good to me! I commented with some fairly unimportant musings about boxing.

/// driver should activate the task if it hasn't run in this long
pub period: Duration,
/// impl of [`BackgroundTask`] that represents the work of the task
pub task_impl: Box<dyn BackgroundTask>,
Copy link
Member

Choose a reason for hiding this comment

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

I wondered about whether it would be nicer to also be generic over a T: BackgroundTask and make boxing it the responsibility of the driver, but that would mean that Driver::register gets monomorphized separately for every background task, which seemed unfortunate (although I don't think binary size is as big a concern for Nexus as, e.g. embedded projects...). So, I think the current design seems the best to me.

Copy link
Member

Choose a reason for hiding this comment

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

OTTOH then we could spawn the future unboxed, which means we avoid an additional heap pointer dereference every time the future is polled...but I don't know if we actually care about that overhead, either...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's interesting -- I hadn't considered that. Within Nexus, I think we've usually gone the other way, seeking to reduce monomorphization to decrease compile times. I had some second thoughts on even using generics here to simplify the strings, but I figured there'd be at most 4 cases and probably more like 2, and the convenience for callers is considerable.

My general approach within the control plane is to not worry about straight-line performance at the level of pointer derefs and allocations. I'll almost always choose constructs that seem clearer, easier to use (or harder to misuse), or more debuggable even if they cost a few instructions. I've seen cases where on-CPU performance of the control plane was a problem (either for latency or resource utilization), but almost always because it was pathological, not just a few percent slower than it could be. (Scalability is another question but I think is less often in tension here.)

@davepacheco davepacheco merged commit 0f757cd into main Jul 1, 2024
19 checks passed
@davepacheco davepacheco deleted the dap/task-registration branch July 1, 2024 20:21
hawkw added a commit that referenced this pull request Jul 3, 2024
hawkw added a commit that referenced this pull request Jul 10, 2024
hawkw added a commit that referenced this pull request Jul 17, 2024
hawkw added a commit that referenced this pull request Jul 26, 2024
hawkw added a commit that referenced this pull request Jul 27, 2024
hawkw added a commit that referenced this pull request Jul 30, 2024
hawkw added a commit that referenced this pull request Aug 9, 2024
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