Skip to content

Try reusing memory#15

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

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

Conversation

@pickfire
Copy link

@pickfire pickfire commented Jul 25, 2021

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
Owner

Is it possible to avoid unsafe in this?

@darleybarreto
Copy link

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
Copy link

darleybarreto commented Jul 25, 2021

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
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
Copy link
Owner

avinassh commented Aug 8, 2021

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
Copy link
Author

pickfire commented Aug 9, 2021

What's the difference? 1s?

@avinassh
Copy link
Owner

@pickfire yup, seems so.

@pickfire
Copy link
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