Skip to content

Conversation

@FGasper
Copy link
Collaborator

@FGasper FGasper commented Nov 6, 2025

This optimizes a few BSON marshal/unmarshal operations:

  • Unmarshaling document rechecks
    • This optimizes generation of recheck tasks, which entails reading & unmarshaling rechecks in series.
  • Marshaling VerificationResult and MismatchInfo
    • This optimizes behavior when there are lots of mismatches.

This also includes a new UnmarshalCursor function that works like mongo.Cursor.All but for structs that implement UnmarshalFromBSON (and forbid bson.Unmarshal).

It also fixes 2 intermittently-failing tests:

  • TestChangeStream_Resume_NoSkip
  • TestRecheckDocsWithDstChangeEvents

@FGasper FGasper changed the title Felipe optimize mismatch bson Optimize BSON for rechecks & mismatches. Nov 7, 2025
@FGasper FGasper requested a review from tdq45gj November 7, 2025 22:10
@FGasper FGasper marked this pull request as ready for review November 7, 2025 22:10
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.

LGTM. I've left some minor comments.

Comment on lines +35 to +40
bsonLen := 4 + // header
1 + 4 + 1 + len(bson.ObjectID{}) + // Task
1 + 6 + 1 + len(detail) + // Detail
1 // NUL

buf := make(bson.Raw, 4, bsonLen)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder how much faster it is compared to using DocumentBuilder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

DocumentBuilder doesn’t have a way to preallocate a buffer, unfortunately. Every field it adds does a reallocation.


connStr := os.Getenv("MVTEST_META")
if connStr == "" {
t.Skipf("No MVTEST_META found; skipping.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to use the source or destination URI instead of skipping?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Anything that sets a src or dst in env has probably also set a meta. IMO not worth accommodating something that hasn’t.

Co-authored-by: Jian Guan <61915096+tdq45gj@users.noreply.github.com>
@FGasper FGasper merged commit 67c0de8 into mongodb-labs:main Nov 10, 2025
99 checks passed
@FGasper FGasper deleted the felipe_optimize_mismatch_bson branch November 10, 2025 16:36
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