ext/standard: Optimize array_column() - #23786
Conversation
| RETURN_EMPTY_ARRAY(); | ||
| } | ||
|
|
||
| array_init_size(return_value, num_elements); |
There was a problem hiding this comment.
nit: If I were you, I would put inside each case instead wdyt ?
There was a problem hiding this comment.
did you benchmark when the key is not interned string btw ?
There was a problem hiding this comment.
did you benchmark when the key is not interned string btw ?
The old benchmarks is already running on non-interned keys.
There was a problem hiding this comment.
can you benchmark this one (esp K2 case) ?
<?php
$case = $argv[1];
$N = 200000;
$rt = substr('xid', 1);
$rows = [];
for ($i = 0; $i < $N; $i++) {
$rows[] = ($case === 'K3' || $case === 'K4') ? [$rt => $i] : ['id' => $i];
}
$col = ($case === 'K2' || $case === 'K4') ? $rt : 'id';
$t = [];
for ($r = 0; $r < 25; $r++) {
$s = hrtime(true);
$out = array_column($rows, $col);
$t[] = (hrtime(true) - $s) / 1e6;
unset($out);
}
sort($t);
printf("%.3f\n", $t[12]);There was a problem hiding this comment.
K2 observes ~14% improvements and K3 ~8%. Others are within noise
There was a problem hiding this comment.
not as good locally (~2% for K2) but it s all positive regardless.
There was a problem hiding this comment.
Yeah I am away from productive server testing this stuff on personal PC. So perhaps bigger noise than expected.
|
Thanks! |
Just move some numeric-string key normalization stuff out of the main loop. Also return early for empty input.
'id''0''123456789'