Skip to content

Try reusing memory#15

Open
pickfire wants to merge 1 commit into
avinassh:masterfrom
pickfire:reuse-vec
Open

Try reusing memory#15
pickfire wants to merge 1 commit into
avinassh:masterfrom
pickfire:reuse-vec

Conversation

@pickfire

@pickfire pickfire commented Jul 25, 2021

Copy link
Copy Markdown

Fix #10

Unsafe is probably not nice but I am not sure how to satisfy borrow checker there. I tried using mem::swap and related functions but it still seemed like the borrow checker does not know that the reference is not longer valid when vec.clear().

29s -> 27s

@avinassh

Copy link
Copy Markdown
Owner

Is it possible to avoid unsafe in this?

@darleybarreto

Copy link
Copy Markdown

Is it possible to avoid unsafe in this?

I can't think of anything to help avoid these unsafe here, but I'm not a Rust expert, so...

@darleybarreto

darleybarreto commented Jul 25, 2021

Copy link
Copy Markdown

One thing I tried to do was using named_params!,

for batch in values.iter() {
    let (a,b,c) = batch;
    row_values.push(named_params!{":area": a, ":age": b, ":active": c});
}

but Params is not implemented for &[&[(&str, &dyn ToSql)]], which is the slice from the row_values.

@pickfire

Copy link
Copy Markdown
Author

I switched to use https://docs.rs/rsor/0.1.2/rsor/ rsor library as suggested by @upsuper (he suggested a related library with runtime checks). std does not provide these tools and it only have compile-time cost.

@avinassh

avinassh commented Aug 8, 2021

Copy link
Copy Markdown
Owner

I ran it and I did not see much difference:

./bench.sh
Sun Aug  8 14:06:19 IST 2021 [RUST] basic_batched.rs (100_000_000) inserts

real	0m30.255s
user	0m27.745s
sys	0m2.247s

@pickfire

pickfire commented Aug 9, 2021

Copy link
Copy Markdown
Author

What's the difference? 1s?

@avinassh

Copy link
Copy Markdown
Owner

@pickfire yup, seems so.

@pickfire

Copy link
Copy Markdown
Author

Yeah, but it's consistent 1s and reduced memory allocation, I am not sure how good the effect will be on other parts.

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.

Rust reuse memory

3 participants