Skip to content

Rust reuse memory #10

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

Open
pickfire opened this issue Jul 19, 2021 · 6 comments · May be fixed by #15
Open

Rust reuse memory #10

pickfire opened this issue Jul 19, 2021 · 6 comments · May be fixed by #15

Comments

@pickfire
Copy link

pickfire commented Jul 19, 2021

Rather than creating the Vec in the inner loop, you can create it in the outer loop using with_capacity with capacity of batch size so it will not allocate in inner loop, then just reuse the Vec.

Once the execute is used, can just Vec clear to clear the items without deallocating memory. I wonder how much faster will it make.

@dovahcrow
Copy link

I tried this one and it gives me 9% speed up on the basic_batched benchmark.

@avinassh
Copy link
Owner

damn, thats amazing. Would you like to send a PR @pickfire @dovahcrow

@darleybarreto
Copy link

I would like to see that too. I tried to remove those ::new() from the loops, but I couldn't find a way to make the borrow checker happy.

@pickfire
Copy link
Author

I just tried it, I seemed to have faced issues with borrow checker as well. I just use transmute to increase their lifetime and it worked. But yeah, people is not happy seeing unsafe. &dyn ToSql make it hard for the borrow checker I believe.

pickfire added a commit to pickfire/fast-sqlite3-inserts that referenced this issue Jul 25, 2021
@pickfire pickfire linked a pull request Jul 25, 2021 that will close this issue
pickfire added a commit to pickfire/fast-sqlite3-inserts that referenced this issue Jul 25, 2021
@avinassh
Copy link
Owner

avinassh commented Jul 25, 2021

@pickfire we can have another benchmark code just for unsafe and I don't mind unsafe code. may be we call it as batched_unsafe?

@pickfire
Copy link
Author

@avinassh Without unsafe there is another set of optimization in place, it already have reduced allocations with that patch.

pickfire added a commit to pickfire/fast-sqlite3-inserts that referenced this issue Jul 25, 2021
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 a pull request may close this issue.

4 participants