-
Notifications
You must be signed in to change notification settings - Fork 88
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
performance: optimized string and various other XDS improvements #1016
Conversation
Skipping CI for Draft Pull Request. |
that's more than I thought we'd save, nice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
relatively easy win
/// * Immutable | ||
/// This is mostly provided by a library, ArcStr, we just provide a very thin wrapper around it | ||
/// for some flexibility. | ||
pub type Strng = ArcStr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking we don't need this type alias, we could just have ArcStr + RichStrng(ArcStr)?
That's a little more obvious and it's also easy to look at a type named ArcStr
and know what it does.
But that's mostly a stylistic nit I guess, and if we ever want to use a different ArcStr impl, this insulates from that a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was on the fence about the Strng
thing. It was more useful when doing the interning library since their type name was unwieldy
4c11a76
to
9a55c79
Compare
In response to a cherrypick label: #1016 failed to apply on top of branch "release-1.22":
|
In response to a cherrypick label: new issue created for failed cherrypick: #1020 |
…io#1016) * Initial * wip * prod compiling * bump max * wip diagnostics * performance: avoid clone of workload on conversion * performance: avoid allocating vector for all resources * intern: xds types * performance: optimize endpoint_uid * perf: do not allocate endpoints vector * performance: do not clone services map * use arcstr instead * metrics back on * Tests compile * format * fix and format * Move rbac over too * Move more over * rebase (cherry picked from commit 5eb8906)
* logs: fix dst.namespace and missing dst.service (#1017) (cherry picked from commit 543a45b) * misc: remove Default identity from prod codepath (#1018) We didn't use it anywhere which is good -- but it was a risk (cherry picked from commit a84ce37) * performance: optimized string and various other XDS improvements (#1016) * Initial * wip * prod compiling * bump max * wip diagnostics * performance: avoid clone of workload on conversion * performance: avoid allocating vector for all resources * intern: xds types * performance: optimize endpoint_uid * perf: do not allocate endpoints vector * performance: do not clone services map * use arcstr instead * metrics back on * Tests compile * format * fix and format * Move rbac over too * Move more over * rebase (cherry picked from commit 5eb8906) * add missing local example (#1014) * add missing local example * lint * fmt (cherry picked from commit 3c7fc71) * logging: disable regex (#987) (cherry picked from commit c68413be4387680372df53fb496b50132fb6fef3) (cherry picked from commit 4605fdb) --------- Co-authored-by: Yuval Kohavi <yuval.kohavi@gmail.com>
Fixes #988
This PR introduces a new string representation. See issue above for some more background.
I initially implemented this using
internment::ArcIntern<str>
. This showed improvements over master, but I compared to using ArcStr and found actually better memory utilization with ArcStr, and much less complexity and risk. Conveniently, due to thestrng
module abstracting things, the swap was pretty much trivial (just a few small changes due to different conversion helpers in the libraries). So if we do want to switch things in the future, it shouldn't be too bad.This optimizes the XDS path (and, presumably, others -- but I only measured XDS much).
My test covered 30k pods with 2k services. I loaded this up and checked memory usage (total and peak).
Before: 1.8GB total, 700mb retained
After: 1.1GB total, 520mb retained
Roughly 100mb of improvement came from switching the string representation, and 80mb came from other optimizations. Not confident in that breakdown as I was going back and forth moving things over + optimizing.
All optimizations here are guided by profiling. End profile (github
![2024-05-03_13-31-45](https://private-user-images.githubusercontent.com/623453/327875228-af1c6628-486a-4c77-9442-ad7065e81a0d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg0MDI2MjYsIm5iZiI6MTcxODQwMjMyNiwicGF0aCI6Ii82MjM0NTMvMzI3ODc1MjI4LWFmMWM2NjI4LTQ4NmEtNGM3Ny05NDQyLWFkNzA2NWU4MWEwZC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNjE0JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDYxNFQyMTU4NDZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mZDg3OWVkNTQzNjYyYjZiNTVmYWJkMzhkODllNmY3OTUwNTJiMzBiYmQ4ODA0NjI1ODZlYzE4YzYzMmVkODgwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.p2TY2m6uMtCLlhbAVznkT6ptRSZZmTzcTahpBITV73E)
Not much low hanging fruit left, most of the memory is in our hashmaps.
Optimizations aside from string changes: