[php-src] PR #22648: Optimize array_diff() for long values

From: Date: Thu, 09 Jul 2026 08:26:53 +0000
Subject: [php-src] PR #22648: Optimize array_diff() for long values
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-36928@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/22648 Author: mehmetcansahin ## Summary This adds a fast path for array_diff() when all compared values are integers. Instead of converting values to temporary strings, the implementation builds an integer-keyed exclude map and copies values from the first array when they are not present in that map. Mixed-type inputs still fall back to the existing generic implementation, preserving current comparison behavior. ## Benchmark ```php $a = range(0, 200000); $b = range(100000, 300000); $start = microtime(true); for ($i = 0; $i < 10; $i++) { array_diff($a, $b); } printf("%.3fs\n", microtime(true) - $start); ``` Before: ~0.12s, after: ~0.024s (~5x faster). ## Tests - make -j8 - ./sapi/cli/php run-tests.php -n -q ext/standard/tests/array/array_diff*.phpt (50/50 pass) The new test covers integer values, negative values, min/max integers, duplicate values, key preservation, string fallback cases, multiple exclude arrays, references, and empty results.

« previous php.git-pulls (#36928) next »