Skip to content

Conversation

@patrickfreed
Copy link
Contributor

SWIFT-1072

This PR contains the driver-side changes of SWIFT-1072. This also is the only change required for the find performance improvements as well, making this the last PR of SWIFT-993.

Benchmark results (insertion ones copied from PR on swift-bson):

benchmark libbson based median time target time (1.25x) unoptimized swift-bson post-optimizations
small doc bulk insert 0.096 0.12 4258.673 0.117
large doc bulk insert 0.332 0.415 59.637 0.454
small doc insertOne 3.258 4.0725 8.276 3.412
large doc insertOne 0.327 0.409 28.742 0.456
findOne by _id 4.07 5.088 229.7 3.837
find and empty cursor small doc 0.468 0.585 10436.246 0.498
find and empty cursor large doc 0.032 0.040 105.365 0.043

@patrickfreed patrickfreed requested a review from kmahar January 27, 2021 22:04
for upsert in upserted.compactMap({ $0.documentValue }) {
guard let index = upsert["index"]?.toInt() else {
throw MongoError.InternalError(message: "Could not cast upserted index to `Int`")
var seenKey = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to start out as false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yep, good catch, fixed.

guard let index = upsert["index"]?.toInt() else {
throw MongoError.InternalError(message: "Could not cast upserted index to `Int`")
var seenKey = true
for (k, v) in reply {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest adding a comment somewhere indicating that this method is written this way for perf reasons so we can do it in a single pass, seems maybe easy to forget otherwise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@patrickfreed patrickfreed merged commit 6bba3ed into mongodb:master Jan 28, 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 this pull request may close these issues.

2 participants