Skip to content

Commit 8d65a70

Browse files
authored
RUST-867 Document some performance best practices (#466)
1 parent fd0f75c commit 8d65a70

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/client/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ const DEFAULT_SERVER_SELECTION_TIMEOUT: Duration = Duration::from_secs(30);
6969
/// # Ok(())
7070
/// # }
7171
/// ```
72+
/// ## Notes on performance
73+
/// Spawning many asynchronous tasks that use the driver concurrently like this is often the best
74+
/// way to achieve maximum performance, as the driver is designed to work well in such situations.
75+
///
76+
/// Additionally, using a custom Rust type that implements `Serialize` and `Deserialize` as the
77+
/// generic parameter of [`Collection`](../struct.Collection.html) instead of [`bson::Document`] can
78+
/// reduce the amount of time the driver and your application spends serializing and deserializing
79+
/// BSON, which can also lead to increased performance.
7280
///
7381
/// ## TCP Keepalive
7482
/// TCP keepalive is enabled by default with ``tcp_keepalive_time`` set to 120 seconds. The

src/coll/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,9 @@ where
11351135

11361136
/// Inserts the data in `docs` into the collection.
11371137
///
1138+
/// Note that this method accepts both owned and borrowed values, so the input documents
1139+
/// do not need to be cloned in order to be passed in.
1140+
///
11381141
/// This operation will retry once upon failure if the connection and encountered error support
11391142
/// retryability. See the documentation
11401143
/// [here](https://docs.mongodb.com/manual/core/retryable-writes/) for more information on
@@ -1149,6 +1152,9 @@ where
11491152

11501153
/// Inserts the data in `docs` into the collection using the provided `ClientSession`.
11511154
///
1155+
/// Note that this method accepts both owned and borrowed values, so the input documents
1156+
/// do not need to be cloned in order to be passed in.
1157+
///
11521158
/// This operation will retry once upon failure if the connection and encountered error support
11531159
/// retryability. See the documentation
11541160
/// [here](https://docs.mongodb.com/manual/core/retryable-writes/) for more information on
@@ -1187,6 +1193,9 @@ where
11871193

11881194
/// Inserts `doc` into the collection.
11891195
///
1196+
/// Note that either an owned or borrowed value can be inserted here, so the input document
1197+
/// does not need to be cloned to be passed in.
1198+
///
11901199
/// This operation will retry once upon failure if the connection and encountered error support
11911200
/// retryability. See the documentation
11921201
/// [here](https://docs.mongodb.com/manual/core/retryable-writes/) for more information on
@@ -1201,6 +1210,9 @@ where
12011210

12021211
/// Inserts `doc` into the collection using the provided `ClientSession`.
12031212
///
1213+
/// Note that either an owned or borrowed value can be inserted here, so the input document
1214+
/// does not need to be cloned to be passed in.
1215+
///
12041216
/// This operation will retry once upon failure if the connection and encountered error support
12051217
/// retryability. See the documentation
12061218
/// [here](https://docs.mongodb.com/manual/core/retryable-writes/) for more information on

0 commit comments

Comments
 (0)