forked from istio/ztunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
performance: reduce and test size of futures (istio#985)
* performance: reduce and test size of futures Prior to this PR, each outbound connection future was 22k. This is really big. The reason behind this is how Rust sizes Futures; the stack size is allocated based on the maximum required size through any branch. This means even obscure code paths can bloat up the entire future for everyone. This PR optimizes a bunch of these. This is done in a few ways: * Box::pin expensive futures. While we have to allocate these when we hit them, of course, when we don't hit these codepaths they are now "free". We have a lot of uncommon expensive code paths. Especially HBONE vs passthrough; hbone is way more expensive. But also on demand XDS, DNS, etc * Arc the Config which is large * A variety of other micro-optimizations A new `assertions` module is added to verify we do not regress * Fix the upgrade drop issue * fmt
- Loading branch information
1 parent
4605fdb
commit 7112743
Showing
26 changed files
with
294 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright Istio Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Below helper functions are used to help make about the size of types. | ||
// There are some compile time ways to do this, but they don't work in the way we need for the most part; | ||
// analyzing the size of Futures which we don't have explicit declarations for. | ||
// Future size is determined by the max required stack size for the async function. This means deeply | ||
// branched code can create huge Future's, leading to high per-connection memory usage in ztunnel. | ||
// Debugging these usages can be done by `RUSTFLAGS=-Zprint-type-sizes cargo +nightly build -j 1`, | ||
// or by logging with the functions below. | ||
|
||
#[cfg(all(any(test, feature = "testing"), debug_assertions))] | ||
pub fn size_between_ref<T>(min: usize, max: usize, t: &T) { | ||
let size = std::mem::size_of_val(t); | ||
if size < min || size > max { | ||
// If it is too small: that is good, we just want to update the assertion to be more aggressive | ||
// If it is too big: that is bad. We may need to increase the limit, or consider refactors. | ||
panic!( | ||
"type {} size is unexpected, wanted {min}..{max}, got {size}", | ||
std::any::type_name::<T>(), | ||
) | ||
} | ||
tracing::trace!( | ||
"type {} size is within expectations, wanted {min}..{max}, got {size}", | ||
std::any::type_name::<T>(), | ||
) | ||
} | ||
|
||
#[cfg(not(all(any(test, feature = "testing"), debug_assertions)))] | ||
pub fn size_between_ref<T>(_min: usize, _max: usize, _t: &T) {} | ||
|
||
#[inline(always)] | ||
pub fn size_between<T>(min: usize, max: usize, t: T) -> T { | ||
size_between_ref(min, max, &t); | ||
t | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.