Commit 9569f22
committed
Performance: avoid over-allocation in wp_is_numeric_array()
When a trace of allocations revealed that `wp_is_numeric_array()`
accounted for a significant fraction of the allocations in a page
render, it was observed that the function eagerly allocates and copies
array keys and then filters them when all it wants to know is whether a
single key in the array meets a condition.
In this patch the `array_filter( array_keys() )` invocation is replaced
with early-aborting iteration to avoid the memory allocation and
copying.
This patch was prepared as part of WCEU 2026 Contributor Day.
Developed in: WordPress#12100
Discussed in: https://core.trac.wordpress.org/ticket/65467
Follow-up to [34927].
Props dmsnell, westonruter, yusufmudagal.
Fixes #65467.
git-svn-id: https://develop.svn.wordpress.org/trunk@62524 602fd350-edb4-49c9-b593-d223f7449a821 parent 54eca7b commit 9569f22
2 files changed
Lines changed: 40 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5290 | 5290 | | |
5291 | 5291 | | |
5292 | 5292 | | |
| 5293 | + | |
| 5294 | + | |
| 5295 | + | |
| 5296 | + | |
| 5297 | + | |
| 5298 | + | |
| 5299 | + | |
| 5300 | + | |
| 5301 | + | |
| 5302 | + | |
| 5303 | + | |
| 5304 | + | |
| 5305 | + | |
| 5306 | + | |
| 5307 | + | |
| 5308 | + | |
5293 | 5309 | | |
5294 | 5310 | | |
5295 | 5311 | | |
5296 | 5312 | | |
| 5313 | + | |
| 5314 | + | |
5297 | 5315 | | |
5298 | | - | |
| 5316 | + | |
5299 | 5317 | | |
5300 | 5318 | | |
5301 | 5319 | | |
5302 | 5320 | | |
5303 | | - | |
5304 | | - | |
| 5321 | + | |
| 5322 | + | |
| 5323 | + | |
| 5324 | + | |
| 5325 | + | |
5305 | 5326 | | |
5306 | | - | |
| 5327 | + | |
5307 | 5328 | | |
5308 | 5329 | | |
5309 | 5330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
45 | | - | |
| 52 | + | |
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
49 | | - | |
| 56 | + | |
50 | 57 | | |
51 | 58 | | |
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
55 | 62 | | |
56 | 63 | | |
57 | | - | |
| 64 | + | |
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
63 | 70 | | |
64 | 71 | | |
65 | | - | |
| 72 | + | |
66 | 73 | | |
67 | 74 | | |
68 | 75 | | |
| |||
0 commit comments