Found a minor performance fix while debugging why _views_fetch_data_build() is so slow.

Saved about ~80ms on views cache clear.

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Status: Active » Needs review
StatusFileSize
new1.34 KB

Removed the two private functions as they aren't being used.

joelpittet’s picture

Issue summary: View changes
david_garcia’s picture

Just an observation... 80ms out of ~2500 function calls looks to me more profiler overhead than real savings.

The truth is that views_filters_selective_views_data_alter() gets slower as more fields you have declared to views.

Briniging this micro optimization to the limit I would have liked to see something like this:

foreach ($data as $table_name => $table_info) {
    $valid_keys = preg_grep('/$_format|$_i18n|$default/i', array_keys($table_info));
    $table_info = array_intersect_key($table_info, $valid_keys);
    foreach ($table_info as $field_name => $field_info) {
      if (!empty($field_info['filter']['handler']) && $field_info['filter']['handler'] != 'views_handler_filter_selective') {

But no worries, your patch is more than good. I'll commit it soon.

joelpittet’s picture

Title: Inline endsWith function and save ~80ms » Inline endsWith function for performance

Thanks @david_garcia.

The preg_grep() you have there looks a bit off, shouldn't the $ be at the end? And should delta check be removed? What is $default?

Was playing around with it and wasn't getting what I expected so did a variation on that with preg_match that I think would work, hopefully I was following what you were suggesting.


$table_info = [
  'field_field_test_default' => '',
  'field_field_test_format' => '',
  'field_field_test' => '',
  'field_field_test_value' => '',
  'field_field_test_i18n' => '',
  'field_i18nfield_test_' => '',
  'delta' => '',
];
$valid_keys = preg_grep('/$_format|$_i18n|$default/i', array_keys($table_info));
var_dump($valid_keys);

// Maybe more like.
$invalid_keys = preg_grep('/(_format|_i18n)$/i', array_keys($table_info));
$invalid_keys[] = 'delta';
var_dump($invalid_keys);
$valid_keys = array_diff_key($table_info, array_flip($invalid_keys));
var_dump($valid_keys);

joelpittet’s picture

StatusFileSize
new1.24 KB
new1.68 KB

It does have a performance improvement over my original idea so I like that:) I usually don't write off too many things on profiler overhead. Do you have variance that you write-off?

Found a flag to inverse the preg_grep(). So that avoids the array_flip()/array_diff_key() calls from #5

joelpittet’s picture

Issue summary: View changes
StatusFileSize
new232.87 KB

Saved another ~5ms from that change, hopefully my preg_foo() is right.

david_garcia’s picture

Status: Needs review » Fixed

Commited!

I believe that it is impossible to scrap even a microsecond from your last implementation proposal.

My code from #4 was just written on the fly as a POC - I had the idea of using php array related functions to deal with arrays - that's what they are here for.

Thanks!

joelpittet’s picture

Cool, thanks @david_garcia

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.