Skip to content

ZPP: Return tristate from zend_parse_arg_bool_weak() - #21739

Merged
Girgias merged 6 commits into
php:masterfrom
Girgias:zpp-bool-direct-return
May 2, 2026
Merged

ZPP: Return tristate from zend_parse_arg_bool_weak()#21739
Girgias merged 6 commits into
php:masterfrom
Girgias:zpp-bool-direct-return

Conversation

@Girgias

Copy link
Copy Markdown
Member

Follow-up PR on top of #21737.

This idea is based on @ndossche previous PR to reduce codebloat: #18436

This effectively allows us to return the boolean value via the return type rather than using an out pointer.

@github-actions

Copy link
Copy Markdown

AWS x86_64 (c6id.metal)

AttributeValue
Environmentaws
Instance typec6id.metal
Architecturex86_64
CPUIntel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz, 64 cores @ 2900 MHz
CPU settingsdisabled deeper C-states, disabled turbo boost, disabled hyper-threading
RAM251 GB
Kernel6.12.66-88.122.amzn2023.x86_64
OSAmazon Linux 2023.10.20260202
GCC14.2.1
Time2026-04-12 15:10:23 UTC
Job detailshttps://github.com/php/php-src/actions/runs/24309681555 (Artifacts)
Changesethttps://github.com/php/php-src/compare/361084086d..90efcd9280

Laravel 12.11.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@36108400.390340.392270.000330.08%0.390770.00%0.390720.00%2.0890.0001.00024.85 MB
PHP - zpp-bool-direct-return0.388130.389660.000330.09%0.38864-0.54%0.38854-0.56%1.2748.6140.00024.91 MB

Symfony 2.8.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@36108400.670510.675940.000910.14%0.671570.00%0.671360.00%3.0050.0001.00025.25 MB
PHP - zpp-bool-direct-return0.665790.668120.000440.07%0.66638-0.77%0.66626-0.76%1.6928.6140.00025.18 MB

Wordpress 6.9 main page - 50 iterations, 20 warmups, 20 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@36108400.586200.589700.000660.11%0.586950.00%0.586740.00%2.6610.0001.00025.27 MB
PHP - zpp-bool-direct-return0.585730.589170.000770.13%0.58674-0.04%0.58657-0.03%1.3492.5160.01225.15 MB

bench.php - 50 iterations, 20 warmups, 2 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@36108400.444700.446980.000430.10%0.445890.00%0.445880.00%-0.2620.0001.00025.27 MB
PHP - zpp-bool-direct-return0.445130.447450.000490.11%0.446030.03%0.446070.04%0.572-1.2240.22125.15 MB

@Girgias
Girgias marked this pull request as ready for review April 12, 2026 15:49
@Girgias
Girgias requested a review from dstogov as a code ownerApril 12, 2026 15:49

@iluuu1994iluuu1994 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Looks to be profitable.

Comment threadZend/zend_API.h Outdated
@@ -2173,21 +2173,27 @@ ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string

/* Inlined implementations shared by new and old parameter parsing APIs */

typedef enum ZPP_PARSE_BOOL_STATUS {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should just be zpp_parse_bool_status.

Comment threadZend/zend_API.h Outdated
@@ -2173,21 +2173,27 @@ ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string

/* Inlined implementations shared by new and old parameter parsing APIs */

typedef enum ZPP_PARSE_BOOL_STATUS {
ZPP_PARSE_AS_FALSE = 0,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, should have a consistent prefix, i.e. ZPP_PARSE_BOOL_STATUS_FALSE.

Comment threadZend/zend_API.c Outdated
Comment on lines +514 to +520
if (EXPECTED(Z_TYPE_P(arg) <= IS_STRING)) {
if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("bool", arg_num)) {
return 0;
return ZPP_PARSE_ERROR;
}
*dest = zend_is_true(arg);
} else {
return 0;
return zend_is_true(arg);
}
return 1;
return ZPP_PARSE_ERROR;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy path sandwich. Maybe:

if (UNEXPECTED(Z_TYPE_P(arg) >IS_STRING)) {
returnZPP_PARSE_ERROR;
}
if (UNEXPECTED(Z_TYPE_P(arg) ==IS_NULL) && !zend_null_arg_deprecated("bool", arg_num)) {
returnZPP_PARSE_ERROR;
}
returnzend_is_true(arg);

Comment threadZend/zend_API.h Outdated
} else {
return zend_parse_arg_str_slow(arg, dest, arg_num);
return 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent handling with the other cases? I.e. write to and check *dest without a branch? This won't work for zpp_parse_bool_status because of bool coercion, but should work here.

Comment threadZend/zend_vm_def.h
@github-actions

Copy link
Copy Markdown

AWS x86_64 (c6id.metal)

AttributeValue
Environmentaws
Instance typec6id.metal
Architecturex86_64
CPUIntel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz, 64 cores @ 2900 MHz
CPU settingsdisabled deeper C-states, disabled turbo boost, disabled hyper-threading
RAM251 GB
Kernel6.12.66-88.122.amzn2023.x86_64
OSAmazon Linux 2023.10.20260202
GCC14.2.1
Time2026-04-14 13:33:51 UTC
Job detailshttps://github.com/php/php-src/actions/runs/24401902179 (Artifacts)
Changesethttps://github.com/php/php-src/compare/b34d90606f..5c689b48f7

Laravel 12.11.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@b34d9060.388760.390200.000370.10%0.389170.00%0.389060.00%1.2190.0001.00024.85 MB
PHP - zpp-bool-direct-return0.388510.390990.000410.11%0.38898-0.05%0.38888-0.05%2.7923.3850.00124.90 MB

Symfony 2.8.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@b34d9060.665370.667230.000380.06%0.665880.00%0.665830.00%1.2590.0001.00025.25 MB
PHP - zpp-bool-direct-return0.668110.671260.000720.11%0.668860.45%0.668580.41%1.673-8.6140.00025.17 MB

Wordpress 6.9 main page - 50 iterations, 20 warmups, 20 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@b34d9060.586880.589810.000670.11%0.587740.00%0.587580.00%1.8350.0001.00025.26 MB
PHP - zpp-bool-direct-return0.585670.588400.000470.08%0.58633-0.24%0.58625-0.23%2.3678.0690.00025.14 MB

bench.php - 50 iterations, 20 warmups, 2 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@b34d9060.444390.447230.000570.13%0.446170.00%0.446220.00%-0.5970.0001.00025.26 MB
PHP - zpp-bool-direct-return0.445050.449310.000630.14%0.44598-0.04%0.44600-0.05%2.8712.4680.01425.14 MB

@Girgias

Copy link
Copy Markdown
MemberAuthor

@iluuu1994 so either something in the review comment drastically changed how profitable it is, or the benchmarks have too much noise/jitter :|

@Girgias
Girgiasforce-pushed the zpp-bool-direct-return branch from 5c689b4 to f5e072dCompareApril 21, 2026 12:32
@github-actions

Copy link
Copy Markdown

AWS x86_64 (c6id.metal)

AttributeValue
Environmentaws
Instance typec6id.metal
Architecturex86_64
CPUIntel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz, 64 cores @ 2900 MHz
CPU settingsdisabled deeper C-states, disabled turbo boost, disabled hyper-threading
RAM251 GB
Kernel6.12.66-88.122.amzn2023.x86_64
OSAmazon Linux 2023.10.20260202
GCC14.2.1
Time2026-04-21 12:33:57 UTC
Job detailshttps://github.com/php/php-src/actions/runs/24722544802 (Artifacts)
Changesethttps://github.com/php/php-src/compare/fc9a4a3866..f5e072dae8

Laravel 12.11.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@fc9a4a30.389440.390840.000330.09%0.390030.00%0.389960.00%0.6840.0001.00025.33 MB
PHP - zpp-bool-direct-return0.388310.390500.000530.14%0.38892-0.29%0.38871-0.32%1.6267.4760.00025.32 MB

Symfony 2.8.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@fc9a4a30.664600.670630.001290.19%0.665600.00%0.665140.00%2.6310.0001.00025.26 MB
PHP - zpp-bool-direct-return0.668680.671060.000550.08%0.669490.58%0.669410.64%0.784-7.9310.00025.36 MB

Wordpress 6.9 main page - 50 iterations, 20 warmups, 20 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@fc9a4a30.587550.590020.000480.08%0.588150.00%0.588060.00%2.2410.0001.00025.33 MB
PHP - zpp-bool-direct-return0.586290.589740.000620.11%0.58703-0.19%0.58682-0.21%2.1387.6070.00025.32 MB

bench.php - 50 iterations, 20 warmups, 2 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@fc9a4a30.445830.449100.000590.13%0.446860.00%0.446830.00%0.9910.0001.00025.33 MB
PHP - zpp-bool-direct-return0.445670.447330.000370.08%0.44653-0.07%0.44654-0.06%-0.0223.1750.00225.32 MB

@github-actions

Copy link
Copy Markdown

AWS x86_64 (c6id.metal)

AttributeValue
Environmentaws
Instance typec6id.metal
Architecturex86_64
CPUIntel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz, 64 cores @ 2900 MHz
CPU settingsdisabled deeper C-states, disabled turbo boost, disabled hyper-threading
RAM251 GB
Kernel6.12.66-88.122.amzn2023.x86_64
OSAmazon Linux 2023.10.20260202
GCC14.2.1
Time2026-04-22 02:22:49 UTC
Job detailshttps://github.com/php/php-src/actions/runs/24756115436 (Artifacts)
Changesethttps://github.com/php/php-src/compare/fc9a4a3866..f5e072dae8

Laravel 12.11.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@fc9a4a30.387460.389000.000320.08%0.387880.00%0.387810.00%1.5040.0001.00025.32 MB
PHP - zpp-bool-direct-return0.386100.387440.000270.07%0.38652-0.35%0.38650-0.34%1.1488.6140.00025.31 MB

Symfony 2.8.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@fc9a4a30.662110.670260.001430.22%0.663380.00%0.662950.00%3.0130.0001.00025.25 MB
PHP - zpp-bool-direct-return0.666150.670040.000690.10%0.667580.63%0.667500.69%0.880-8.0140.00025.35 MB

Wordpress 6.9 main page - 50 iterations, 20 warmups, 20 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@fc9a4a30.585970.588240.000520.09%0.586460.00%0.586300.00%2.2910.0001.00025.32 MB
PHP - zpp-bool-direct-return0.584120.586520.000470.08%0.58488-0.27%0.58471-0.27%1.4338.3790.00025.31 MB

bench.php - 50 iterations, 20 warmups, 2 requests (sec)

PHPMinMaxStd devRel std dev %MeanMean diff %MedianMedian diff %SkewnessZ-statP-valueMemory
PHP - baseline@fc9a4a30.445780.447770.000510.11%0.446800.00%0.446830.00%-0.1760.0001.00025.32 MB
PHP - zpp-bool-direct-return0.445580.447650.000490.11%0.44651-0.07%0.44653-0.07%0.3162.9160.00425.31 MB

@Girgias
Girgiasforce-pushed the zpp-bool-direct-return branch 2 times, most recently from 3fea5ce to 0f406e0CompareApril 27, 2026 15:38
This idea is based on @ndossche previous PR to reduce codebloat: php#18436
This idea is based on @ndossche previous PR to reduce codebloat: php#18436
We can use NAN as a sentinel value as neither int nor string value can actually hold a NAN value.
This idea is based on @ndossche previous PR to reduce codebloat: php#18436
This effectively allows us to return the boolean value via the return type rather than using an out pointer.
@Girgias
Girgiasforce-pushed the zpp-bool-direct-return branch from 0f406e0 to 7bfbf8eCompareApril 29, 2026 07:06
@Girgias
Girgias merged commit b9f64f7 into php:masterMay 2, 2026
19 checks passed
@Girgias
Girgias deleted the zpp-bool-direct-return branch May 2, 2026 14:37
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Girgias@iluuu1994