[JAVA-4608] Optimize IdHoldingBsonWriter Created: 11/May/22  Updated: 28/Oct/23  Resolved: 21/May/22

Status: Closed
Project: Java Driver
Component/s: Performance
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Improvement Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed

 Description   

Microbenchmark of insert indicates that ~5% of time is spent in IdHoldingBsonWriter#getIdBsonWriter . An analysis of the code shows that in the normal case (when the document contains a simple _id value like an ObjectId), then it's not necessary to even call this method. We should consider optimizing this class to remove unnecessary calls to this method.

The main issue with the method appears to be the creation of a BasicOutputBuffer, which in turns creates a 1K byte array. We generally pool large buffers like this, but this is a case where the pool is not used. So a couple of other options would be to use a pooled buffer here, or dramatically shrink its size by using the constructor which allows it to be specified.



 Comments   
Comment by Githook User [ 21/May/22 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Remove unnecessary buffer allocation in IdHoldingBsonWriter (#947)

JAVA-4608
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/3485793ece0b79a76bea55a28baef7ae7fded559

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