Skip to content

Conversation

@FGasper
Copy link
Collaborator

@FGasper FGasper commented Oct 29, 2025

This alters document comparison to use a batch cursor instead of the Go driver’s cursor. The advantage here is that, instead of creating giant slices of documents (which are copied from the driver), we’ll read the raw documents directly from the server response buffer. This minimizes GC pressure.

Pprof analysis shows that before this change, slices.Clone() allocated more heap than any other functions. With this change, those allocations are gone.

PR #153 will make the change stream use the same batch cursor.

@FGasper FGasper changed the title Rep 6766 batch cursor compare REP-6766 Compare documents using a batch cursor Oct 29, 2025
@FGasper FGasper marked this pull request as ready for review October 30, 2025 00:53
@FGasper FGasper requested a review from tdq45gj October 30, 2025 00:53
Copy link
Collaborator

@tdq45gj tdq45gj left a comment

Choose a reason for hiding this comment

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

I've left some non-blocking questions. Thanks!

Comment on lines +731 to +733
if err == nil {
c.SetSession(mongo.SessionFromContext(ctx))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason why SetSession is exported and called in the verifier code? Can we set the session in the cursor constructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had it that way for a bit, but then we’d need 2 constructors (one with a session & the other without).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I’m starting to wonder, though, if it should always require a session. The driver does some funny-business under the hood to ensure that cursors always send the same LSID as the initial request.

@FGasper FGasper merged commit d98f02c into mongodb-labs:main Oct 31, 2025
99 checks passed
@FGasper FGasper deleted the REP-6766-batch-cursor-compare branch October 31, 2025 15:08
FGasper added a commit that referenced this pull request Nov 4, 2025
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