You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my case, when pagequery the collections in mongodb, which size more than 1000, such as mongoTemplate.find(new Query().limit(1000),xxx.class)
the cost time of querying is too much, and then I find some reason in the code as:
The point is new ArrayList() ?! , which length of the list is 1000,this means the list will be copyed 18 times, I think the funtion getAndPrepareCollection() which one returns the bean of MongoCollection.java,and this bean has a funtion called countDocuments(), so how about code like this:
Introducing a call to collections.countDocuments() introduces another I/O operation that outweighs its benefit if the result is empty or contains a small number of documents. Why don't you use the stream() method that bypasses ArrayList creation entirely?
mp911de
changed the title
org.springframework.data.mongodb.core.MongoTemplate#executeFindMultiInternal should be optimizedMongoTemplate#executeFindMultiInternal allocations could be optimized
Sep 16, 2022
In my case, when pagequery the collections in mongodb, which size more than 1000, such as
mongoTemplate.find(new Query().limit(1000),xxx.class)
the cost time of querying is too much, and then I find some reason in the code as:
The point is
new ArrayList()
?! , which length of the list is 1000,this means the list will be copyed 18 times, I think the funtiongetAndPrepareCollection()
which one returns the bean ofMongoCollection.java
,and this bean has a funtion calledcountDocuments()
, so how about code like this:The code would reduce the funtcion:java.util.ArrayList#grow be called and save time
The text was updated successfully, but these errors were encountered: