Skip to content
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

MongoTemplate performance issue during call to find() #4846

Closed
clucacicerqlar opened this issue Dec 2, 2024 · 4 comments
Closed

MongoTemplate performance issue during call to find() #4846

clucacicerqlar opened this issue Dec 2, 2024 · 4 comments
Assignees
Labels
type: task A general task

Comments

@clucacicerqlar
Copy link

While using spring-data-mongodb version 4.2.12, Ive noticed that MongoTemplate during a call to find/doFind also performs getMappedSortObject using the original query object. The resulting variable mappedSort is also not even used if isDebugEnabled is FALSE.

In some cases, this call to getMappedSortObject ends creating lots of PropertyReferenceException which end up calling Throwable fillInStackTrace and perform native/synchronized code so lot of time spent for no reason building stack traces?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 2, 2024
@christophstrobl
Copy link
Member

Thank you @clucacicerqlar. The 4.2.x line is already out of OSS support.
If the problem exists on more recent versions please provide us with a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem and maybe some flame graphs or other data that help us understand the issue better.

@christophstrobl christophstrobl added the status: waiting-for-feedback We need additional information before we can continue label Dec 2, 2024
@clucacicerqlar
Copy link
Author

clucacicerqlar commented Dec 2, 2024

hi @christophstrobl thank you for the reply, indeed the issue is there even in the latest versions, see below.

https://github.com/spring-projects/spring-data-mongodb/blob/main/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java#L2596C12-L2596C22

RE sample, you can see above, its problem is pretty easy to spot. the variable Document mappedSort is never used, outside of below IF, and neither in the return function call. so its dead code

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Dec 2, 2024
@christophstrobl
Copy link
Member

thank you @clucacicerqlar for bringing this to our attention!

@christophstrobl christophstrobl added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Dec 9, 2024
@christophstrobl
Copy link
Member

Getting rid of the PropertyReferenceException is long overdue, so thank you for giving us another nudge in that direction. We've opened spring-projects/spring-data-commons#3220 to capture ideas and flesh out details.

For now, we'll make sure the additional sort mapping happens only if debug logging is turned on.

christophstrobl added a commit that referenced this issue Dec 11, 2024
christophstrobl added a commit that referenced this issue Dec 11, 2024
Make sure type used in protected method is visible in defined scope.

See: #4846
christophstrobl added a commit that referenced this issue Dec 11, 2024
@christophstrobl christophstrobl added this to the 4.3.7 (2024.0.7) milestone Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

No branches or pull requests

3 participants