# The death of `#ifndef FAST_ZPP`?

- Thread: https://externals.io/message/93072
- Original archive: https://news-web.php.net/php.internals/93072
- Started by Andrea Faulds on 2016-05-04T16:11:43+00:00
- Messages: 18
- RFC: Fast Parameter Parsing API (Implemented (PHP 7.0)) — https://externals.io/rfc/fast_zpp.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #93072 — Andrea Faulds — 2016-05-04T16:11:43+00:00

URL: https://externals.io/message/93072#93072

Hi everyone,

You may recall that PHP 7.0 introduced a new API for processing 
arguments to internal functions, the "Fast Parameter Parsing API" or 
FAST_ZPP (https://wiki.php.net/rfc/fast_zpp), which is an alternative to 
the existing zend_parse_parameters function family.

Since FAST_ZPP was implemented, many functions in built-in PHP 
extensions look like this:

#ifndef FAST_ZPP
	if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &str, &what) == 
FAILURE) {
		return;
	}
#else
	ZEND_PARSE_PARAMETERS_START(1, 2)
		Z_PARAM_STR(str)
		Z_PARAM_OPTIONAL
		Z_PARAM_STR(what)
	ZEND_PARSE_PARAMETERS_END();
#endif

That is, they have /two/ sets of parameter processing code: one using 
the old API, and one using the new API, with conditional compilation. 
This is necessary because it is still possible to turn off FAST_ZPP by 
changing the value of the macro.

However, should that be the case? The FAST_ZPP RFC was approved and PHP 
7.0 was released containing it enabled by default, so it's no longer 
just an experimental performance enhancement. Furthermore, I have no 
reason to believe that the option to turn off FAST_ZPP is actually used 
in practice, though feel free to prove me wrong!

Requiring all usages of FAST_ZPP to be accompanied by a 
zend_parse_parameters() fallback creates code bloat. It also creates 
hidden, potentially build-breaking bugs, because the code is rarely 
built with FAST_ZPP disabled. It's like the old TSRMLS_CC situation.

Furthermore, for those who would prefer the FAST_ZPP API, it is 
inconvenient that they cannot use it exclusively and must also use 
zend_parse_parameters(), doubling the effort.

So, I would like to ask: would there be any objections to going through 
and removing all unnecessary zend_parse_parameters fallbacks, and making 
it impossible to disable FAST_ZPP? This would make the two APIs equally 
valid.

Thanks!

-- 
Andrea Faulds
https://ajf.me/

---

## #94983 — Andrea Faulds — 2016-08-10T02:23:23+00:00

URL: https://externals.io/message/93072#94983 · In reply to: #93072

Hi everyone,

3 months and 6 days on, nobody has responded to this.

Will these chunks of dead code ever be removed?

Thanks!

Andrea Faulds wrote:
> Hi everyone,
>
> You may recall that PHP 7.0 introduced a new API for processing
> arguments to internal functions, the "Fast Parameter Parsing API" or
> FAST_ZPP (https://wiki.php.net/rfc/fast_zpp), which is an alternative to
> the existing zend_parse_parameters function family.
>
> Since FAST_ZPP was implemented, many functions in built-in PHP
> extensions look like this:
>
> #ifndef FAST_ZPP
>      if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &str, &what) ==
> FAILURE) {
>          return;
>      }
> #else
>      ZEND_PARSE_PARAMETERS_START(1, 2)
>          Z_PARAM_STR(str)
>          Z_PARAM_OPTIONAL
>          Z_PARAM_STR(what)
>      ZEND_PARSE_PARAMETERS_END();
> #endif
>
> That is, they have /two/ sets of parameter processing code: one using
> the old API, and one using the new API, with conditional compilation.
> This is necessary because it is still possible to turn off FAST_ZPP by
> changing the value of the macro.
>
> However, should that be the case? The FAST_ZPP RFC was approved and PHP
> 7.0 was released containing it enabled by default, so it's no longer
> just an experimental performance enhancement. Furthermore, I have no
> reason to believe that the option to turn off FAST_ZPP is actually used
> in practice, though feel free to prove me wrong!
>
> Requiring all usages of FAST_ZPP to be accompanied by a
> zend_parse_parameters() fallback creates code bloat. It also creates
> hidden, potentially build-breaking bugs, because the code is rarely
> built with FAST_ZPP disabled. It's like the old TSRMLS_CC situation.
>
> Furthermore, for those who would prefer the FAST_ZPP API, it is
> inconvenient that they cannot use it exclusively and must also use
> zend_parse_parameters(), doubling the effort.
>
> So, I would like to ask: would there be any objections to going through
> and removing all unnecessary zend_parse_parameters fallbacks, and making
> it impossible to disable FAST_ZPP? This would make the two APIs equally
> valid.
>
> Thanks!
>


-- 
Andrea Faulds
https://ajf.me/

---

## #94984 — Levi Morrison — 2016-08-10T02:35:31+00:00

URL: https://externals.io/message/93072#94984 · In reply to: #94983

> Hi everyone,
>
> 3 months and 6 days on, nobody has responded to this.
>
> Will these chunks of dead code ever be removed?
>
> Thanks!
>
>
> Andrea Faulds wrote:
>
> > […]
>
> --
> Andrea Faulds
> https://ajf.me/
>
> --
> 
> 
>

No objection from me.

---

## #94985 — Yasuo Ohgaki — 2016-08-10T03:07:47+00:00

URL: https://externals.io/message/93072#94985 · In reply to: #94983

Hi Andrea,


> 3 months and 6 days on, nobody has responded to this.
>
> Will these chunks of dead code ever be removed?

I've asked the same question before I start eliminating old style parse API.

Dimitry said it's designed to optimize heavily called functions, not
for ease of use and the RFC for fast zpp states "keep old parameter
parsing API", so I don't have to bother.

+1 for enabling always (No #ifndef FAST_ZPP) and using FIRST_ZPP for
core PHP functions.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #95015 — Fleshgrinder — 2016-08-10T17:19:38+00:00

URL: https://externals.io/message/93072#95015 · In reply to: #94983

> Hi everyone,
> 
> 3 months and 6 days on, nobody has responded to this.
> 
> Will these chunks of dead code ever be removed?
> 
> Thanks!
> 
> Andrea Faulds wrote:
> 

+1 from my side, if it's faster it's faster. :)

-- 
Richard "Fleshgrinder" Fussenegger

---

## #95016 — Andrea Faulds — 2016-08-10T17:23:15+00:00

URL: https://externals.io/message/93072#95016 · In reply to: #94985

Hi Yasuo,

Yasuo Ohgaki wrote:
> I've asked the same question before I start eliminating old style parse API.
>
> Dimitry said it's designed to optimize heavily called functions, not
> for ease of use and the RFC for fast zpp states "keep old parameter
> parsing API", so I don't have to bother.

Oh, yeah, I've heard about that. Even if it wasn't specifically intended 
to be a friendlier API, though, I've heard at least one other person say 
they prefer using FAST_ZPP, and I prefer it myself. It's more verbose, 
but it's easier to read at-a-glance, and it makes mistakes more obvious.

Thanks.

-- 
Andrea Faulds
https://ajf.me/

---

## #95678 — Andrea Faulds — 2016-09-05T22:33:23+00:00

URL: https://externals.io/message/93072#95678 · In reply to: #94983

Hi again,

I finally wrote a patch to get rid of it:

https://github.com/php/php-src/pull/2118

Perhaps this will go somewhere. :)

-- 
Andrea Faulds
https://ajf.me/

---

## #95750 — Ferenc Kovacs — 2016-09-07T13:23:40+00:00

URL: https://externals.io/message/93072#95750 · In reply to: #95678

> Hi again,
>
> I finally wrote a patch to get rid of it:
>
> https://github.com/php/php-src/pull/2118
>
> Perhaps this will go somewhere. :)
>
>
> --
> Andrea Faulds
> https://ajf.me/
>
> --
> 
> 
>
>
+1 from me on the idea.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

---

## #95752 — Zeev Suraski — 2016-09-07T13:28:40+00:00

URL: https://externals.io/message/93072#95752 · In reply to: #95750

> -----Original Message-----
> From: Ferenc Kovacs [mailto:tyra3l@gmail.com]
> Sent: Wednesday, September 07, 2016 4:24 PM
> To: Andrea Faulds <ajf@ajf.me>
> Cc: PHP Internals <internals@lists.php.net>
> Subject: Re: [PHP-DEV] Re: The death of `#ifndef FAST_ZPP`?
> 
> 
> 
> > […]
> +1 from me on the idea.

+1 from me as well.

Zeev

---

## #95754 — Christoph M. Becker — 2016-09-07T15:21:10+00:00

URL: https://externals.io/message/93072#95754 · In reply to: #93072

> Since FAST_ZPP was implemented, many functions in built-in PHP
> extensions look like this:
>
> […]
>
> That is, they have /two/ sets of parameter processing code: one using
> the old API, and one using the new API, with conditional compilation.
> This is necessary because it is still possible to turn off FAST_ZPP by
> changing the value of the macro.
> 
> However, should that be the case? The FAST_ZPP RFC was approved and PHP
> 7.0 was released containing it enabled by default, so it's no longer
> just an experimental performance enhancement. 

It seems to me that the FAST_ZPP macro is not (only) to disable an
experimental feature, but rather to be able to reduce the size of the
built binaries.  I've just checked a `./configure --disable-all`:

  with FAST_ZPP:    16,651,912
  without FAST_ZPP: 16,276,152

That's a difference of 375,760 bytes, but only 2% increase.

> Furthermore, I have no
> reason to believe that the option to turn off FAST_ZPP is actually used
> in practice, though feel free to prove me wrong!

Perhaps that is so, because FAST_ZPP can't be turned of via ./configure.

> Requiring all usages of FAST_ZPP to be accompanied by a
> zend_parse_parameters() fallback creates code bloat. It also creates
> hidden, potentially build-breaking bugs, because the code is rarely
> built with FAST_ZPP disabled. It's like the old TSRMLS_CC situation.
> 
> Furthermore, for those who would prefer the FAST_ZPP API, it is
> inconvenient that they cannot use it exclusively and must also use
> zend_parse_parameters(), doubling the effort.

Valid points.

> So, I would like to ask: would there be any objections to going through
> and removing all unnecessary zend_parse_parameters fallbacks, and making
> it impossible to disable FAST_ZPP? This would make the two APIs equally
> valid.

All in all, I think that the benefits of using only one of the parameter
parsing APIs per function outweigh the drawbacks, so I'm +1 on the
removal of the FAST_ZPP macro.

-- 
Christoph M. Becker

---

## #95755 — Andrea Faulds — 2016-09-07T15:26:46+00:00

URL: https://externals.io/message/93072#95755 · In reply to: #95754

Hi Christoph,

Christoph M. Becker wrote:
> 
>
> It seems to me that the FAST_ZPP macro is not (only) to disable an
> experimental feature, but rather to be able to reduce the size of the
> built binaries.  I've just checked a `./configure --disable-all`:
>
>    with FAST_ZPP:    16,651,912
>    without FAST_ZPP: 16,276,152
>
> That's a difference of 375,760 bytes, but only 2% increase.

This is a fair point. Functions using Fast ZPP have larger code size, 
because of aggressive inlining.

If every function used it, I suppose it might bloat the size of the PHP 
binary somewhat.

>
> > […]
>
> Perhaps that is so, because FAST_ZPP can't be turned of via ./configure.

That's true, but I don't know if there was any reason to add such an option.

In any case, thanks to some uncaught bugs in dead code, no stable 
release of PHP 7 has been able to compile with FAST_ZPP disabled anyway, 
which means I can be certain nobody is using it.

Thanks for your input.

-- 
Andrea Faulds
https://ajf.me/

---

## #95813 — Christoph M. Becker — 2016-09-08T22:20:59+00:00

URL: https://externals.io/message/93072#95813 · In reply to: #95755

Hi Andrea!



> Christoph M. Becker wrote:
>
> > […]
> 
> This is a fair point. Functions using Fast ZPP have larger code size,
> because of aggressive inlining.
> 
> If every function used it, I suppose it might bloat the size of the PHP
> binary somewhat.

And probably for no good reason.  The performance overhead of
zend_parse_parameters() can probably be ignored for a lot of functions,
and while it is somewhat harder to read, besides it's being
space-saving, it is way easier to debug.

There are, however, functions that would greatly benefit from using the
fast ZPP API (e.g. imagecolorat(), see commit 0bf11d1e), so I'd welcome
code reviews regarding (fast) ZPP.

> In any case, thanks to some uncaught bugs in dead code, no stable
> release of PHP 7 has been able to compile with FAST_ZPP disabled anyway,
> which means I can be certain nobody is using it.

I have successfully compiled a recent master with FAST_ZPP undefined.
While that was with `--disable-all`, I can imagine that some extensions
would also compile, so perhaps somebody actually uses that feature.
However, even if that is the case, I don't see necessity to do so.

-- 
Christoph M. Becker

---

## #95881 — Andrea Faulds — 2016-09-09T23:33:32+00:00

URL: https://externals.io/message/93072#95881 · In reply to: #95813

Hi Cristoph,

Christoph M. Becker wrote:
> > […]
>
> I have successfully compiled a recent master with FAST_ZPP undefined.
> While that was with `--disable-all`, I can imagine that some extensions
> would also compile, so perhaps somebody actually uses that feature.
> However, even if that is the case, I don't see necessity to do so.

Ah, yes, you can compile it now, but you couldn't a few days ago when 
the broken code that'd been in there since September hadn't yet been 
fixed. ;)

-- 
Andrea Faulds
https://ajf.me/

---

## #95883 — Christoph M. Becker — 2016-09-09T23:56:26+00:00

URL: https://externals.io/message/93072#95883 · In reply to: #95881

Hi Andrea!



> Christoph M. Becker wrote:
>
> > […]
> 
> Ah, yes, you can compile it now, but you couldn't a few days ago when
> the broken code that'd been in there since September hadn't yet been
> fixed. ;)

Oh, I see.

-- 
Christoph M. Becker

---

## #95919 — Andrea Faulds — 2016-09-11T21:57:48+00:00

URL: https://externals.io/message/93072#95919 · In reply to: #95678

Hi everyone,

Andrea Faulds wrote:
> I finally wrote a patch to get rid of it:
>
> https://github.com/php/php-src/pull/2118
>
> Perhaps this will go somewhere. :)

This has now been merged into PHP-7.0 and up:

https://github.com/php/php-src/commit/d690014bf35507ccb7a1150a27504d2f87848842

Additionally, extra zpp fallback code only found in master has been 
removed here:

https://github.com/php/php-src/commit/3cc90901010f016923e9ca6a4ae15ba08bc18169

Now there is no fallback zpp code around, and Fast ZPP is always enabled.

The FAST_ZPP macro itself remains for compatibility with outside 
extensions, but it doesn't do anything within php-src.

If you're writing a function that needs parameter parsing and which 
targets only PHP 7.0+, you now don't need to (and shouldn't) include zpp 
fallback code if you're using Fast ZPP.

Thanks!
-- 
Andrea Faulds
https://ajf.me/

---

## #95920 — Pierre Joye — 2016-09-12T02:31:26+00:00

URL: https://externals.io/message/93072#95920 · In reply to: #95919

Hi Andrea,


>
> Hi everyone,
>
> Andrea Faulds wrote:
> > […]
>
>
> This has now been merged into PHP-7.0 and up:
>
>
https://github.com/php/php-src/commit/d690014bf35507ccb7a1150a27504d2f87848842
>
> Additionally, extra zpp fallback code only found in master has been
removed here:
>
>
https://github.com/php/php-src/commit/3cc90901010f016923e9ca6a4ae15ba08bc18169
>
> Now there is no fallback zpp code around, and Fast ZPP is always enabled.
>
> The FAST_ZPP macro itself remains for compatibility with outside
extensions, but it doesn't do anything within php-src.
>
> If you're writing a function that needs parameter parsing and which
targets only PHP 7.0+, you now don't need to (and shouldn't) include zpp
fallback code if you're using Fast ZPP.
>
> Thanks!

Thanks you :)

Please add this note to UPGRADING.INTERNALS as well :

Cheers
Pierre

---

## #96004 — Andrea Faulds — 2016-09-15T00:10:43+00:00

URL: https://externals.io/message/93072#96004 · In reply to: #95920

Hi Pierre,

Pierre Joye wrote:
>
> Thanks you :)
>
> Please add this note to UPGRADING.INTERNALS as well :

Well, I was wondering about that, but I don't really know where it 
should be noted.

It's not a user-facing change, in fact nobody was disabling FAST_ZPP 
anyway, so it couldn't be one. Therefore, it shouldn't be noted in NEWS.

And UPGRADING.INTERNALS is an upgrading guide used between major or 
minor releases. This is a patch change that affects not only master, but 
7.1 and 7.0. So it isn't suitable for that, either.

Plus, UPGRADING.INTERNALS has no existing mention of Fast ZPP.

So, it doesn't seem to go anywhere, unfortunately. :/

Thanks.

-- 
Andrea Faulds
https://ajf.me/

---

## #96005 — Pierre Joye — 2016-09-15T04:06:19+00:00

URL: https://externals.io/message/93072#96005 · In reply to: #96004

>
> Hi Pierre,
>
>
> Pierre Joye wrote:
> > […]
>
>
> Well, I was wondering about that, but I don't really know where it should
be noted.
>
> It's not a user-facing change, in fact nobody was disabling FAST_ZPP
anyway, so it couldn't be one. Therefore, it shouldn't be noted in NEWS.
>
> And UPGRADING.INTERNALS is an upgrading guide used between major or minor
releases. This is a patch change that affects not only master, but 7.1 and
7.0. So it isn't suitable for that, either.
>
> Plus, UPGRADING.INTERNALS has no existing mention of Fast ZPP.
>
> So, it doesn't seem to go anywhere, unfortunately. :/
>

It does fit there. It was something we forgot to mention in 7.0 so let fix
that now.

Cheers
Pierre
