Clearing views cache and trying to tackle why the data_alter() is so slow, this was a minor improvement but an improvement nonetheless.

Using isset() can have some nice performance benefits, saved ~80ms in this case.

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

StatusFileSize
new1.19 KB

Tagged with commerce sprint because this is a dependency of commerce_reports.

zany’s picture

Title: Performance views_date_format_sql_views_data_alter() saved ~80ms » Performance enhancement to views_date_format_sql_views_data_alter()
Issue summary: View changes
zany’s picture

I'm happy to rely on `isset()`. It's nicer to look at than `is_array() && array_key_exists()`. Didn't know that it can check nested structures.
Also you got rid of the aliasing in the loop. Is that about performance too, or just personal taste? I'd think it should have worse performance now. But then again it's never so simple.

joelpittet’s picture

@zany my thought on removing the references was that it won't have to set the reference in the loop, though I hardly think that would make or break the patch, the big fix is isset() from is_array() checks.

Quick show of how that will not produce errors:
https://3v4l.org/J2pcc

It would only produce errors I think if field was ever an object... maybe

zany’s picture

Status: Needs review » Closed (fixed)

Thanks.

joelpittet’s picture

Status: Closed (fixed) » Fixed

Thank you @zany for replying so quick. Any chance the patch wasn't pushed?

zany’s picture

I do see it here: http://cgit.drupalcode.org/views_date_format_sql
There is no new release ATM though and the branch is named master not 7.x-3.x like you'd expect.

joelpittet’s picture

Ah i see, thanks. Normally the bot picks up the commit and shows it here. Caught me off guard.

Any chance you could open a dev branch & release for this module?

zany’s picture

The change was simple enough and I went straight to release:)

joelpittet’s picture

Status: Fixed » Needs review

Let's undo the reference change I made:) I was curious about the performance impact about that too from your question.


// Seed data.
foreach (range(0, 1000) as $x) {
  $row = array();
  foreach (range(0, 100) as $y) {
    $row[$y]['field'] = 1;
  }
  $data[uniqid()] = $row;
}
// Copy.
$data2 = $data;

$START = microtime(TRUE);
foreach($data as $module => &$table) {
  foreach($table as $id => &$field) {
    $field['field'] = 1;
  }
}
$END = microtime(TRUE) - $START;
echo "With reference took $END seconds\n";

$start = microtime(TRUE);
foreach ($data2 as $module => $table) {
  foreach ($table as $id => $field) {
    $data[$module][$id]['field'] = 1;
  }
}
$END = microtime(TRUE) - $START;
echo "With keys took $END seconds\n";

echo "Same array? \n";
var_dump($data === $data2);

Results:

With reference took 0.18254899978638 seconds
With keys took 0.47187304496765 seconds

With reference took 0.18951106071472 seconds
With keys took 0.33031606674194 seconds

With reference took 0.18168807029724 seconds
With keys took 0.31012606620789 seconds
zany’s picture

Great to see that you did such a thorough analysis. Usually I'm obsessed about those details too, but I hadn't much time to mess with PHP lately.

joelpittet’s picture

I go in bouts of performance testing:-)

joelpittet’s picture

Want me to propose an interdiff or new patch for master or can you take care of that @zany?

zany’s picture

Status: Needs review » Closed (fixed)

The switch is in http://cgit.drupalcode.org/views_date_format_sql/commit/?id=7458552 and the release 7.x-3.3 was packaged quite quickly for me. Maybe some CDN issue.