Jump to content

Update special PHP 7 functions to use root namespace


Aiwa

Recommended Posts

Posted

PHP 7 added optimization for special PHP functions.  By specifying the root namespace, you can leverage these opcode enhancements and greatly improve performance.  I'd venture a guess there are 1,000's of these function calls in the IPS source.  Difficult to benchmark, but optimistically I'd wager you could easily see a 10-15% performance improvement across the suite.  

See link below for a benchmark on call_user_func(), 68% performance improvement.

https://github.com/Roave/FunctionFQNReplacer

 

Posted

Realistically, you probably won't see that much of an improvement - the interpreter still has overhead when you make a call to an internal function regardless of whether you specify the global namespace or not.

Where possible, variable functions and variable arguments can be used but call_user_func() and its related functions should be used where either of those is questionable.

Posted

it doesn't hurt anything and really cost nothing to implement this, you can add the use function; after the namespace, to "import" a FQF.

namespace \IPS\someapp;
use function in_array, count, is_array, count, etc;

or you can edit all your code to. you can also configure phpstorm (settings|editor|general|auto import|prepend functions and constants from the global space with "\"), to do this for you as you are typing a function name.

as for speed improvements, i've done some test with DT Proxy, as it processes a ton of data. switching over to FQF's (something i had removed with the rewrite) and adding them back in, i can say it improved proxyclass generation by about 8 to 10%. I've done xdebug trace dumps before of IPS, with several hundred internal methods calls per page load, this could speed up things a decent amount on php 7+ servers. 

Posted

We'll look into this, thanks for bringing it up. ? My hunch is a change like this would be held for a major release, however, just because we'd be updating a lot of files on our side.

Posted
1 hour ago, bfarber said:

We'll look into this, thanks for bringing it up. ? My hunch is a change like this would be held for a major release, however, just because we'd be updating a lot of files on our side.

working on a parser class, that will iterate thru a folder, and automagically add backslashes to T_FUNCTIONS that don't already have them ? (which will have a cli component to it, so you can add it to a git hook).

Posted
3 hours ago, bfarber said:

We'll look into this, thanks for bringing it up. ? My hunch is a change like this would be held for a major release, however, just because we'd be updating a lot of files on our side.

That's fair.  

Whenever you guys have a chance to review, I'd be interested in your decision and what you find while researching.  I've done a reasonable amount of research on it, enough to see that the only downside is time to update source.  Outside of that, there are only benefits...  Backwards compatible with 5.6, no change in opcodes... Eventually everyone will have to get on board with 7 and be able to leverage the opcode enhancements, the sooner they do the more impressed they'd be. 

15 hours ago, Anatik said:

Realistically, you probably won't see that much of an improvement - the interpreter still has overhead when you make a call to an internal function regardless of whether you specify the global namespace or not.

Where possible, variable functions and variable arguments can be used but call_user_func() and its related functions should be used where either of those is questionable.

I don't think you read the linked references... This isn't just about call_user_func() and comparable functions.  in_array(), is_array(), count(), array_slice(), get_called_class(), and many more... call_user_func() was just a handy example... 

Of course the interpreter still has overhead, but you can't deny that using PHP 7 and leveraging the benefit of fewer opcodes, for however many 1,000's of times these functions are called, by simply specifying the root namespace will result in a performance improvement.  

Posted

DevToolbox now includes "slasher.php" which can iterate thru a directory and parses the php files in it, to look for php internal functions and constants to backslash ? it preserves the whitespace and all that jazz in the file. hint hint @bfarber ?

 

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...