catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

Performance improve #312

Closed munggruel closed 7 years ago

munggruel commented 9 years ago

select cause have a foreach preg_match

protected function data_implode($data, $conjunctor, $outer_conjunctor = null) { $wheres = array(); foreach ($data as $key => $value) { $type = gettype($value); if ( preg_match("/^(AND|OR)(\s+#.*)?$/i", $key, $relation_match) && $type == 'array' ) { $wheres[] = 0 !== count(array_diff_key($value, array_keys(array_keys($value)))) ? '(' . $this->data_implode($value, ' ' . $relation_match[1]) . ')' : '(' . $this->inner_conjunct($value, ' ' . $relation_match[1], $conjunctor) . ')'; } else { preg_match('/(#?)([\w.-]+)([(>|>\=|<|<\=|!|<>|><|!?~)])?/i', $key, $match); $column = $this->column_quote($match[2]);

munggruel commented 9 years ago

foreach 多次 preg_match 性能不太好,能否改进一下

munggruel commented 9 years ago

我用 xhprof 分析过,Medoo 除了PDO连接 和 查询 占了 20%时间,Meedo类 解析 sql语句也花了 20%时间,有些长

munggruel commented 9 years ago

递归 循环 嵌套 多重正则,所以性能不行啊,求递归展开,还有这个 count(array_diff_key($value, array_keys(array_keys($value)))),性能也不咋的

munggruel commented 9 years ago

写成 array_values($value) !== $value 替换 0 !== count(array_diff_key($value, array_keys(array_keys($value)))), 因为 ['0'=>0, '1'=>1] 这种情况并不会发生