-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Optimize BSON codec lookup. #1632
Conversation
- Use `BsonTypeCodecMap` for decoding in `BsonArray` to enable faster access. - Optimize `BsonTypeClassMap` by replacing `Map` with a plain array to eliminate redundant hash computations. JAVA-5339
JAVA-5339
JAVA-5339
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.
Looks good - a couple of questions mainly for my edification
annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.37' | ||
} | ||
|
||
tasks.register("jmh", JavaExec) { |
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.
Does this get run via evergreen in the same way the other benchmarks do?
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.
Currently, no. I initially considered adding it to Evergreen, but it would expand this PR and would require some time to test it. This task is mainly for local benchmarking to quickly assess the relative performance impact of small components. However, I think we should consider adding it to Evergreen in the future, as it could provide more insight into performance changes.
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.
In that case in the future it may be worth splitting jmh benchmarks into their own project.
For example reorganize both into a benchmarks folder but have separate configuration for each:
benchmarks
|
| - driver (the current driver-benchmarks)
| - jmh (jmh test suite)
Nothing to do now.
driver-benchmarks/src/main/com/mongodb/benchmark/jmh/codec/BsonArrayCodecBenchmark.java
Outdated
Show resolved
Hide resolved
driver-benchmarks/src/main/com/mongodb/benchmark/jmh/codec/BsonDocumentBenchmark.java
Outdated
Show resolved
Hide resolved
Using ordinal() ties the mapping to enum declaration order, which risks subtle bugs in the future. JAVA-5339
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.
I have added some suggestions - that reduce the import footprint but realisitcally will have little to no impact on the jmh tests - so are optional nit fixes.
LGTM
driver-benchmarks/src/main/com/mongodb/benchmark/jmh/codec/BsonArrayCodecBenchmark.java
Outdated
Show resolved
Hide resolved
driver-benchmarks/src/main/com/mongodb/benchmark/jmh/codec/BsonDocumentBenchmark.java
Outdated
Show resolved
Hide resolved
driver-benchmarks/src/main/com/mongodb/benchmark/jmh/codec/BsonDocumentBenchmark.java
Outdated
Show resolved
Hide resolved
driver-benchmarks/src/main/com/mongodb/benchmark/jmh/codec/BsonArrayCodecBenchmark.java
Outdated
Show resolved
Hide resolved
driver-benchmarks/src/main/com/mongodb/benchmark/jmh/codec/BsonUtils.java
Outdated
Show resolved
Hide resolved
driver-benchmarks/src/main/com/mongodb/benchmark/jmh/codec/BsonUtils.java
Outdated
Show resolved
Hide resolved
driver-benchmarks/src/main/com/mongodb/benchmark/jmh/codec/BsonUtils.java
Show resolved
Hide resolved
…nArrayCodecBenchmark.java Co-authored-by: Ross Lawley <ross.lawley@gmail.com>
…nDocumentBenchmark.java Co-authored-by: Ross Lawley <ross.lawley@gmail.com>
…nDocumentBenchmark.java Co-authored-by: Ross Lawley <ross.lawley@gmail.com>
…nArrayCodecBenchmark.java Co-authored-by: Ross Lawley <ross.lawley@gmail.com>
…nUtils.java Co-authored-by: Ross Lawley <ross.lawley@gmail.com>
…nUtils.java Co-authored-by: Ross Lawley <ross.lawley@gmail.com>
JAVA-5339
JAVA-5339
This PR introduces performance optimizations for BSON encoding and decoding to improve efficiency for both BsonArrayCodec BsonDocumentCodec in codec lookups. The latest benchmarks:
BsonArrayCodec:
BsonDocumentCodec:
The BsonDocumentBenchmark parses simple BsonInt32 fields to minimize the impact of other codecs to evaluate BsonDocumentCodec's internal performance.
Changes:
BsonTypeCodecMap
for encoding and decoding inBsonArrayCodec
andBsonDocumentCodec
to enable faster access.BsonTypeClassMap
by replacingMap
with a plain array to eliminate redundant hash computations.JAVA-5339