[JAVA-5307] Address low hanging fruit in performance benchmarks Created: 31/Jan/24  Updated: 01/Feb/24

Status: Needs Triage
Project: Java Driver
Component/s: Performance
Affects Version/s: None
Fix Version/s: None

Type: Epic Priority: Unknown
Reporter: Jeffrey Yemin Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Scope Cost Estimate: 0
Cost to Date: 0
Final Cost Estimate: 0
Cost Threshold %: 100

 Description   

We should take a close look at the driver's performance benchmark results and look for opportunities to improve. As an example, some of the things observed while running the large doc bulk insert benchmark:

  • Use of java.util.Stack in BsonWriter implementations. All the methods of this class are synchronized, which is unnecessary in non-thread safe classes. Could use ArrayDeque instead.
  • Lots of calls to CodecRegistry#get in DocumentCodec#writeValue and {BsonDocumentCodec#writeValue}}. The implementation of this method in ProvidersCodecRegistry is not built for use in inner loops. Some caching within the Codec implementation could be useful here.
  • ByteBufferBsonOutput is great for minimizing heap use, but there is a performance cost of all the buffer management that it has to do in an inner loop. We can consider using a simpler implementation of OutputBuffer that trades off memory use for speed. For example, we could just cache 48MB buffers instead of power-of-two buffers.

There are likely more opportunities available as well.



 Comments   
Comment by Jeffrey Yemin [ 01/Feb/24 ]

Quick and dirty implementation of the above ideas: https://github.com/jyemin/mongo-java-driver/tree/j5307

Generated at Thu Feb 08 09:04:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.