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
Code snippet
\Magento\Framework\Profiler::start('category-collection-timer');
$collection = $this->_categoryCollectionFactory->create()->addFieldToFilter('is_feature',1)->addAttributeToSelect(['name', 'is_active', 'parent_id', 'image'])->setStoreId($this->_storeManager->getStore()->getId())->setPageSize(8)->setCurPage(1) ;
\Magento\Framework\Profiler::stop('category-collection-timer');
Code snippet
\Magento\Framework\Profiler::start('category-list-timer');
$featuredFilter=$this->filterBuilder->setField('is_feature')->setValue('1')->setConditionType("eq")->create();
$activeFilter=$this->filterBuilder->setField('is_active')->setValue('1')->setConditionType("eq")->create();
$group1=$this->filterGroupBuilder->addFilter($featuredFilter)->create();
$group2=$this->filterGroupBuilder->addFilter($activeFilter)->create();
$searchCriteria=$this->searchCriteriaBuilder->setFilterGroups([$group1,$group2])->create();
$searchCriteria->setPageSize(8)->setCurrentPage(1);
$categorylistresults=$this->categoryList->getList($searchCriteria);
$categories=$categorylistresults->getItems();
\Magento\Framework\Profiler::start('category-list-timer');