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

fix(s2n-quic-dc): make debug assertions cheaper for TCP accept manager #2419

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

camshaft
Copy link
Contributor

@camshaft camshaft commented Dec 12, 2024

Description of changes:

The current invariants check in tcp::tokio::manager ends up being quite expensive, especially when the backlog is large - basically O(N^2). Instead, I made them collect all of the indexes into a vec and sort them before comparing. This ends up being quite a bit cheaper than what we were doing before.

I also made a slight change to the free list behavior. Instead of pushing back free workers it pushes them to the front. The effect is that we only end up using N workers, where N is the number of concurrent connections. In theory, this should reduce memory churn, though it might be overall quite small. But I thought it couldn't hurt.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@camshaft camshaft marked this pull request as ready for review December 12, 2024 02:49
@camshaft camshaft force-pushed the camshaft/dc-debug-opt branch from 7d3cae6 to f7e3e71 Compare December 12, 2024 14:48
.chain(self.by_sojourn_time.iter(&self.workers))
.collect::<Vec<_>>();
linked_workers.sort();
assert!((0..self.workers.len()).eq(linked_workers.iter().copied()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably need an assert! that the linked_workers has the same length? I guess sort of implies with free.iter, but maybe doesn't hurt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Iterator::eq should also check the length: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.eq

assert_eq!([1].iter().eq([1].iter()), true);
assert_eq!([1].iter().eq([1, 2].iter()), false);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, I'm distinctly remembering some kind of oops around this... maybe just bad memory.

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 had the same memory at first. There are some that so have that issue, like zip.

@camshaft camshaft merged commit 5dd0c47 into main Dec 13, 2024
129 checks passed
@camshaft camshaft deleted the camshaft/dc-debug-opt branch December 13, 2024 03:08
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