spring-projects/spring-data-mongodb

MongoTemplate performance issue during call to find()

clucacicerqlar opened this issue · 4 comments

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?

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.

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

thank you @clucacicerqlar for bringing this to our attention!