thedodd / wither

An ODM for MongoDB built on the official MongoDB Rust driver.
https://docs.rs/wither
Other
324 stars 40 forks source link

db.clone() performance concern #57

Closed mehmetsefabalik closed 3 years ago

mehmetsefabalik commented 4 years ago

I see in the examples that db.clone() should be given to function. Isn't it a performance issue? Is there nicer API? why should one use wither rather than official driver?

thedodd commented 4 years ago

@mehmetsefabalik

Isn't it a performance issue? Is there nicer API?

So, the pattern that is currently in place is actually a hold-over form the original driver (the prototype which the mongo team published before the current official driver was created). Now that you mention it, I will look into making an update to the current alpha release to use references instead of clones.

Previously, the Database object from the driver was an Arc type, so cloning wasn't a big deal. Now, it looks like it actually carries some other data along with the inner client/connection. So it is definitely going to be more of a performance issue now. Thanks for bringing this to my attention!

why should one use wither rather than official driver?

As is stated in the first line of the README: The primary goal of this project is to provide a simple, sane & predictable interface into MongoDB based on data models.

Using Wither, you are able to deal with your collections by way of data models, instead of some cobbled together BSON. That is the core value add.

Moreover, Wither just re-exports the mongodb driver & the bson crate. It is expected that you will use both. As is also stated in that same paragraph of the README: If at any point this system might get in your way, you have direct access to the underlying driver.

So, IMHO it is really just a matter of whether you prefer to interface with mongo in a more structured, data-first approach using your data models (your structs). If you do not, then you probably won't get much from this project :).


@mehmetsefabalik thanks for pointing out the now-unnecessary use of db.clone(). I'll definitely update the code to follow the new driver's reference-based pattern.

mehmetsefabalik commented 4 years ago

Thanks for the reply! It is so explanatory. I will spend time with the project, maybe I can contribute, too.

thedodd commented 4 years ago

@mehmetsefabalik that would be great. There are definitely lots of features to implement.

You are more than welcome to look into the interface updates mentioned here as well.

thedodd commented 3 years ago

@mehmetsefabalik just wanted to follow-up with you. I finally got around to knocking this out. It is released as part of 0.9.0-alpha.2. Let me know what you think. All in all, it was a dead simple change.

mehmetsefabalik commented 3 years ago

Great to see the improvement! Keep up the good work.