[JAVA-4020] Expose a new parameter to pass FindOptions for find operations in MongoCollection Created: 23/Feb/21 Updated: 27/Oct/23 Resolved: 12/Mar/21 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | 4.2.1 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | James Chen | Assignee: | Jeffrey Yemin |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Description |
The constructor of com.mongodb.reactivestreams.client.internal.FindPublisherImpl#FindPublisherImpl creates a new instance of FindOptions, which is a waste of memory. And MongoCollection doesn't allow developers to pass the instance of FindOptions (while update/count/delete operations allow passing their options) We want to pass our own FindOptions instance to avoid recreating the same FindOptions instance.
1. Expose a new parameter to pass FindOptions for find operations in MongoCollection 2. Allow pass custom FindOptions to com.mongodb.reactivestreams.client.internal.FindPublisherImpl#FindPublisherImpl |
| Comments |
| Comment by Backlog - Core Eng Program Management Team [ 12/Mar/21 ] |
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information. |
| Comment by James Chen [ 23/Feb/21 ] |
|
@Jeffrey Yemin, thank you for your quick reply, We don't have a plan to measure and benchmark the performance improvement currently. These tickets may be just low priority, but can be considered as an improvement to both memory and code maintainability in mongo-java-driver (the same for the ticket https://jira.mongodb.org/browse/JAVA-4021 (Use Update/Find/Delete/...Options as a context in Find/...Operation class to avoid copying)) in future releases. And after going through the code review of mongo-java-driver, the change to allow users to pass FindOptions seems not a difficult thing and can keep code consistent with other operations in com.mongodb.reactivestreams.client.MongoCollection (they all support accept an Options parameter). About https://jira.mongodb.org/browse/JAVA-4021 , it can not only just avoid allocating duplicate objects but also eliminate error-prone code that redeclares all options twice (e.g. one in FindOptions and another in FindOperations) for better maintainability and code clarity. |
| Comment by Jeffrey Yemin [ 23/Feb/21 ] |
|
Have you been able to demonstrate that the requested change results in a measurable and significant performance improvement in either throughput or latency? If so, we would consider it, but our experience has been that optimizations like this tend not to result in a noticeable improvement. Consider that this is just one of many, many short-lived objects that are created as a result of a single database operation (often in the context of an HTTP request inside an application server), and getting rid of just one of those objects is not likely to improve performance significantly. Also consider that Java runtimes are now quite efficient at garbage-collecting short-lived objects. Do you have evidence that any FindOptions instances are living long enough to be promoted to the tenured generation and require collection via a major GC collection? If so, it's possible that tuning your garbage collector would be beneficial to your application. |