Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
k-samuel committed Oct 31, 2021
2 parents 903b94e + c0a4ac4 commit d4c7188
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RoadRunner or Swoole.

The library is optimized for performance at the expense of RAM consumption.

[Changelog](./changelog.md)

## Install

Expand All @@ -24,13 +25,26 @@ composer require k-samuel/faceted-search

Tests on sets of products with 10 attributes, search with filters by 3 fields.

| Items count | Memory | Find | Get Filters | Sort by field| Results Found |
|----------------:|---------:|-----------------:|-----------------------:|-------------:|-----------------:|
| 10,000 | ~7Mb | ~0.0009 s. | ~0.01 s. | ~0.001 s. | 922 |
| 50,000 | ~48Mb | ~0.011 s. | ~0.15 s. | ~0.01 s. | 4565 |
| 100,000 | ~98Mb | ~0.015 s. | ~0.20 s. | ~0.01 s. | 9163 |
| 300,000 | ~236Mb | ~0.049 s. | ~0.63 s. | ~0.11 s. | 27191 |
| 1000,000 | ~820Mb | ~0.209 s. | ~2.38 s. | ~0.47 s. | 90070 |
PHP 7.4.21 (no xdebug extension)

| Items count | Memory | Find | Get Filters (aggregates) | Sort by field| Results Found |
|----------------:|---------:|-----------------:|-------------------------:|-------------:|-----------------:|
| 10,000 | ~7Mb | ~0.0004 s. | ~0.003 s. | ~0.001 s. | 866 |
| 50,000 | ~49Mb | ~0.004 s. | ~0.02 s. | ~0.007 s. | 4538 |
| 100,000 | ~98Mb | ~0.008 s. | ~0.05 s. | ~0.01 s. | 8993 |
| 300,000 | ~236Mb | ~0.034 s. | ~0.18 s. | ~0.11 s. | 27281 |
| 1000,000 | ~820Mb | ~0.126 s. | ~0.76 s. | ~0.44 s. | 89403 |

PHP 8.0.12 + JIT (no xdebug extension)

| Items count | Memory | Find | Get Filters (aggregates) | Sort by field| Results Found |
|----------------:|---------:|-----------------:|-------------------------:|-------------:|-----------------:|
| 10,000 | ~7Mb | ~0.0004 s. | ~0.003 s. | ~0.001 s. | 866 |
| 50,000 | ~49Mb | ~0.007 s. | ~0.03 s. | ~0.008 s. | 4538 |
| 100,000 | ~98Mb | ~0.016 s. | ~0.07 s. | ~0.02 s. | 8993 |
| 300,000 | ~236Mb | ~0.047 s. | ~0.23 s. | ~0.15 s. | 27281 |
| 1000,000 | ~820Mb | ~0.164 s. | ~0.86 s. | ~0.46 s. | 89403 |


* Items count - Products in index
* Memory - RAM used for index
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog

### v1.2.8 (31.10.2021)
Up to 50% acceleration of aggregates
* Performance optimization for aggregates (getFilters). Reduced the number of passes for filter aggregates.
* PHP 8 performance tests added
* Readme updated with performance test comparison (php7/php8)
### v1.2.7 (07.10.2021)
* Small performance enhancements
* Performance tests update
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "k-samuel/faceted-search",
"version": "1.2.7",
"version": "1.2.8",
"type": "library",
"description": "PHP Faceted search",
"keywords": ["php","faceted search"],
Expand Down
19 changes: 15 additions & 4 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private function findFilters(array $filters = [], array $inputRecords = [], bool
$result = [];
$facetsData = $this->index->getData();
$indexedFilters = [];
$filteredRecords = [];

if(!empty($filters)){
// index filters by field
Expand All @@ -112,6 +113,10 @@ private function findFilters(array $filters = [], array $inputRecords = [], bool
*/
$indexedFilters[$filter->getFieldName()] = $filter;
}
$filteredRecords = $this->find($indexedFilters, $inputRecords);
if(!empty($filteredRecords)){
$filteredRecords = array_flip($filteredRecords);
}
}

foreach ($facetsData as $filterName => $filterValues) {
Expand All @@ -127,11 +132,17 @@ private function findFilters(array $filters = [], array $inputRecords = [], bool
}else{
$filtersCopy = $indexedFilters;
// do not apply self filtering
unset($filtersCopy[$filterName]);
$recordIds = $this->find($filtersCopy, $inputRecords);
if(!empty($recordIds)){
$recordIds = array_flip($recordIds);
if(isset($filtersCopy[$filterName])){
unset($filtersCopy[$filterName]);
$recordIds = $this->find($filtersCopy, $inputRecords);
if(!empty($recordIds)){
$recordIds = array_flip($recordIds);
}
}else{
$recordIds = $filteredRecords;
}


foreach ($filterValues as $filterValue => $data) {
// need to count values
if($countValues){
Expand Down
2 changes: 1 addition & 1 deletion tests/performance/create_dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

$dataSet = [];

for ($i = 1; $i < $resultsCount; $i++) {
for ($i = 1; $i <= $resultsCount; $i++) {
$countWh = rand(0, count($warehouses));
$wh = [];
for ($k = 0; $k < $countWh; $k++) {
Expand Down
3 changes: 2 additions & 1 deletion tests/performance/find.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

$index = new Index();
$index->setData($indexData);

$count = count($index->getAllRecordId());
$resultData[] = ['Total items', (string) $count,''];
$resultData[] = ['Index memory usage', (string) $memUse. "Mb",''];
$resultData[] = ['Loading time', number_format($time,6) . 's', ''];

Expand Down

0 comments on commit d4c7188

Please sign in to comment.