[JAVA-5067] Improve efficiency of first() Method in MongoIterableImpl Created: 11/Jul/23  Updated: 17/Jul/23

Status: Backlog
Project: Java Driver
Component/s: Query Operations
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Slav Babanin Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

The current implementation of the first() method in MongoIterableImpl creates a BatchCursor and calls the next() method to retrieve only the first entry. However, underlying readOperation is created with the batch size specified by the user. As a result, a call to the server is made to retrieve documents in batches, even though only the first element is returned by the first() method.

It leads to inefficient utilization of system resources, including heap memory, and places undue pressure on the server and network. To resolve this issue, it is recommended to optimize the first() method by ensuring that the readOperation is created with a batch size of 1.


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