-
Couldn't load subscription status.
- Fork 15
Optimize BSON & GC handling. #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This code gets called repeatedly, so it’s worth optimizing. This also optimizes the field-names uniqueness check.
05f1ea5 to
2868f19
Compare
Unmarshaling is slow due to reflection. This function gets called frequently enough to justify the optimization.
66c7611 to
31a3273
Compare
31a3273 to
899476f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I have two questions for my curiosity, but none of them is blocking.
mbson/raw_value.go
Outdated
| strLen := len(typedIn) | ||
| buf := make([]byte, 5+strLen) | ||
|
|
||
| binary.LittleEndian.PutUint32(buf, 1+uint32(strLen)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I understanding it correctly that it is safe because all BSON values are little-endian except timestamp and counter values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All BSON numbers are little-endian, yeah. http://bsonspec.org
| // if the target type doesn’t match the value. | ||
| // | ||
| // Augment bsonType if you find a type here that’s missing. | ||
| func CastRawValue[T bsonCastRecipient](in bson.RawValue) (T, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function and ToRawValue seems to be re-implementing driver's logic. I wonder if the driver has the same functions or do we have to implement these ourselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call … I found AppendInt32/Int64/String and have replaced them in here.
This makes the document IDs easier to reason about and sets up further optimizations. It also adds a few “shortcut” utilities to marshal/unmarshal BSON without reflection.
This fixes a typo that caused more recheck batches than was intended. It’s merely a small performance fix; it does not impact correctness.
This minimizes GC overhead, especially from BSON marshaling.
899476f to
5afa227
Compare
This PR contains several commits that optimize various aspects of BSON handling & garbage-collection.
The commits will be preserved in the merge. Review should consider each individually.