I am trying to refactor get category data method. Initially, it was written with Collection filter. Later I refactored with the search builder interface.

When I tried to compare the querying time, I found the Collection query seems to be faster.

Here is a performance difference.

Can we assume that filtering through the collection factory is faster than a search criteria builder?

1st collection method

2nd search criteria enter image description here

Code snippet

$collection = $this->_categoryCollectionFactory->create()->addFieldToFilter('is_feature',1)->addAttributeToSelect(['name', 'is_active', 'parent_id', 'image'])->setStoreId($this->_storeManager->getStore()->getId())->setPageSize(8)->setCurPage(1) ;

Code snippet

  • two queries are not same
    – Sohel Rana
    Commented Jun 13, 2020 at 17:32
  • @sohel I will verify and repost the queries again. I would like to know if there is difference in performance between search builder and collection factories
    – blakcaps
    Commented Jun 14, 2020 at 1:25
  • The answer is no. But still, your both query are not the same. The first one returns count value, 2nd one returns all data. That's why you saw the difference.
    – Sohel Rana
    Commented Jun 14, 2020 at 6:14


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.