PackedHashtableOptimization
info on by default PHP ≥ 7.0Group: Performance · PhpStorm name: PackedHashtableOptimizationInspection
Since PHP 7 an array whose keys are integers inserted in ascending order can be stored in a compact "packed" layout. An array literal that lists integer keys out of order (numeric-string keys count as the integers PHP stores them as) misses that layout. Sorting the keys lets the engine use it.
Example
php
<?php
$grid = [
5 => 'e', 3 => 'c', 9 => 'i'
];
$cells = array(
-1 => 'a', -4 => 'b', 0 => 'c', 2 => 'd'
);
$mixed = array('7' => 1, '2' => 2, 9 => 3);
$names = ['3' => 'x', 4 => 'y', '8' => 'z']; // already stored as integers
$small = [2 => 'b', 1 => 'a'];
$sorted = [1 => 'a', 2 => 'b', 2 => 'c'];
$labels = ['3' => 'x', 'label' => 'y', 5 => 'z'];
$padded = ['07' => 'x', 8 => 'y', 9 => 'z'];
$dyn = [$k => 1, 4 => 2, 6 => 3];
$plain = ['a', 'b', 'c'];
$float = [3.5 => 'a', 2 => 'b', 1 => 'c'];Reported:
- line 2: Sort the integer keys ascending so the array can be stored packed.
- line 5: Sort the integer keys ascending so the array can be stored packed.
- line 8: Sort the integer keys ascending so the array can be stored packed.
Configure
In custos.json:
json
{
"rules": {
"PackedHashtableOptimization": {
"enabled": false
}
}
}Suppress
Before the statement or declaration (or the first statement of the file), either of:
php
// @custos-ignore PackedHashtableOptimization
/**
* @noinspection PackedHashtableOptimizationInspection
*/