-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
perf: Change PlSmallStr
impl from Arc<str>
to compact_str
#18508
Merged
Conversation
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
nameexhaustion
force-pushed
the
pl-str-impl
branch
from
September 2, 2024 06:01
4de270e
to
b52b396
Compare
github-actions
bot
added
internal
An internal refactor or improvement
rust
Related to Rust Polars
labels
Sep 2, 2024
nameexhaustion
force-pushed
the
pl-str-impl
branch
from
September 2, 2024 06:03
b52b396
to
a76969d
Compare
nameexhaustion
commented
Sep 2, 2024
#[inline(always)] | ||
pub fn from_static(s: &'static str) -> Self { | ||
Self(Arc::from(s)) | ||
pub const fn from_static(s: &'static str) -> Self { |
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.
We are now const fn
for from_static
nameexhaustion
commented
Sep 2, 2024
nameexhaustion
force-pushed
the
pl-str-impl
branch
from
September 2, 2024 06:17
9397a86
to
a76969d
Compare
nameexhaustion
force-pushed
the
pl-str-impl
branch
from
September 2, 2024 07:23
c42892f
to
f3e8717
Compare
nameexhaustion
changed the title
refactor(rust): Change
refactor(rust): Change Sep 2, 2024
PlSmallStr
impl from Arc<str>
to kstring
PlSmallStr
impl from Arc<str>
to compact_str
nameexhaustion
requested review from
ritchie46,
orlp,
c-peters and
alexander-beedie
as code owners
September 2, 2024 09:40
ritchie46
changed the title
refactor(rust): Change
perf: Change Sep 2, 2024
PlSmallStr
impl from Arc<str>
to compact_str
PlSmallStr
impl from Arc<str>
to compact_str
github-actions
bot
added
performance
Performance issues or improvements
python
Related to Python Polars
labels
Sep 2, 2024
I marked this as a |
Internal benchmarks: use std::hint::black_box;
use std::sync::Arc;
use std::time::Duration;
use compact_str::CompactString;
fn bench_multithread_clone<T: Clone + Send + 'static>(n_iters: usize, n_threads: usize, value: T) -> Duration {
let start = std::time::Instant::now();
let mut threads = Vec::with_capacity(n_threads);
for _ in 0..n_threads {
let value = value.clone();
threads.push(
std::thread::spawn(move || {
for _ in 0..n_iters {
black_box(value.clone());
}
})
);
}
for t in threads {
t.join().unwrap();
}
start.elapsed()
}
fn main() {
let n_iters = 10_000_000;
let n_threads = 10;
for logsz in 0..11 {
let sz = 1 << logsz;
let s = "a".repeat(sz);
println!("String {sz}: {:?}", bench_multithread_clone(n_iters, n_threads, s.clone()));
println!("Arc<str> {sz}: {:?}", bench_multithread_clone(n_iters, n_threads, Arc::from_iter(s.chars())));
println!("Compact {sz}: {:?}", bench_multithread_clone(n_iters, n_threads, CompactString::from(&s)));
}
} High contention
Lower contention
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
accepted
Ready for implementation
internal
An internal refactor or improvement
performance
Performance issues or improvements
python
Related to Python Polars
rust
Related to Rust Polars
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
compact_str
for small-string in-lining, and after testing also preferred againstArc<str>
/kstring<arc>
as the atomic ref-counting performed badly under contentionPlSmallStr::const_default()
with more ergonomicPlSmallStr::EMPTY