[PHP-DEV] Constant propagation inside same compilation unit

2019-09-18 Thread Benjamin Coutu
ud then include/require files that define global constants before compiling files that contain those constants, thereby propagating their values throughout the code base during preloading. That would eliminate a lot of the runtime cost of (not so truly constant) constants. Please let me know your

[PHP-DEV] Optimize zend_string equality check with hash key

2019-04-05 Thread Benjamin Coutu
Thoughts? -- Benjamin Coutu ben.co...@zeyos.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-DEV] Unnecessary overhead in getdate()

2018-03-29 Thread Benjamin Coutu
only call `time(NULL)` when `!ZEND_NUM_ARGS()`. Can someone please make the appropriate change? Please apologize, but I simply review code and do not have a proper C development setup that allows me to supply patches or create pull requests. Thanks, Ben -- Benjamin Coutu http://www.zeyos.com

Re: [PHP-DEV] Apply substr() optimization to array_slice()

2017-10-27 Thread Benjamin Coutu
: Nikita Popov Date: Fri, 27 Oct 2017 18:34:15 +0200 Subject: Re: [PHP-DEV] Apply substr() optimization to array_slice() > > > On Fri, Oct 27, 2017 at 12:10 PM, Nikita Popov wrote: > > On Fri, Oct 27, 2017 at 4:16 PM, Sara Golemon wrote: > >> > >> On Fri, Oct 27

[PHP-DEV] Apply substr() optimization to array_slice()

2017-10-27 Thread Benjamin Coutu
Hello everyone, Please consider these two statements: substr($string, 0, $length); array_slice($array, 0, $length, true); Currently, with substr(), if $offset is zero and $length is smaller or equal to the original string length we just increase the reference count of the original string and r

Re: [PHP-DEV] Basic string comparison functions still use old parameter parsing API

2017-06-07 Thread Benjamin Coutu
6/7/2017 7:15 PM, Benjamin Coutu wrote: > > Hi Dmitry, > > > > I just noticed that all basic string comparison functions in > > Zend/zend_builtin_functions.c, especially "strcmp", "strncmp", > > "strcasecmp", "strncasecmp" st

[PHP-DEV] Basic string comparison functions still use old parameter parsing API

2017-06-07 Thread Benjamin Coutu
ecmp", etc. at least as important as "substr_compare", especially considering that these are wrappers around very basic functions that often get called in very hot code or inside tight loops (e.g. sorting). I therefore recommend changing those 4 functions in Zend/zend_builtin_func

Re: [PHP-DEV] Algorithmic efficiency of zend_memrchr

2016-11-03 Thread Benjamin Coutu
== Original == From: Levi Morrison To: Benjamin Coutu Date: Thu, 03 Nov 2016 13:23:23 +0100 Subject: Re: [PHP-DEV] Algorithmic efficiency of zend_memrchr > > > On Thu, Nov 3, 2016 at 5:21 AM, Benjamin Coutu wrote: > > Hello everyone, > > > > I think there ar

[PHP-DEV] Algorithmic efficiency of zend_memrchr

2016-11-03 Thread Benjamin Coutu
rther? Cheers, Benjamin Coutu -- Bejamin Coutu ben.co...@zeyos.com ZeyOS, Inc. http://www.zeyos.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] Directly embed small strings in zvals

2016-10-27 Thread Benjamin Coutu
Ouch, forgot my powers of two there during a weak moment - what a careless mistake. Sorry about that! Given the low entropy I highly doubt this to be of much benefit. == Original == From: Lauri Kenttä To: Benjamin Coutu Date: Thu, 27 Oct 2016 17:12:15 +0200 Subject: Re: [PHP

Re: [PHP-DEV] Directly embed small strings in zvals

2016-10-27 Thread Benjamin Coutu
o, no need to ever unpack if we can guarantee that all eligible strings are converted to packed format before usage) Let me know if you (or anyone else) is interested in discussing this approach further. Cheers, Benjamin Coutu == Original == From: Benjamin Coutu To: Nikita Popov

Re: [PHP-DEV] Exploit fully packed array/hash property

2016-10-19 Thread Benjamin Coutu
loops. This would not entail any overhead on write. What do you think? Cheers, Benjamin == Original == From: Dmitry Stogov To: Benjamin Coutu , Xinchen Hui , Nikita Popov , Joe Watkins , "Bob Weinand" , Andrea Faulds Date: Wed, 19 Oct 2016 18:02:53 +0200 Subject:

[PHP-DEV] Exploit fully packed array/hash property

2016-10-19 Thread Benjamin Coutu
Hello everyone, I've identified a few more array/hash use cases where it might make sense to introduce special short circuit logic for packed arrays. Specifically, there is an additional property of certain packed arrays (apart from being packed obviously) that we can utilize: A packed array wi

[PHP-DEV] Directly embed small strings in zvals

2016-09-13 Thread Benjamin Coutu
Hello everyone, I was wondering if it would make sense to store small strings (length <= 7) directly inside the zval struct, thereby avoiding the need to extra allocate a zend_string, which would also not entail any costly indirection and refcounting for such strings. The idea would be to add

Re: [PHP-DEV] More packed hash optimizations in array.c

2016-08-06 Thread Benjamin Coutu
Hi Xinchen, There is still a way we could make this work, if we'd simply check for nNumUsed == nNumOfElements as well. Because a packed array with nNumUsed equal to nNumOfElements must be consecutively indexed from zero onward without any gaps (no IS_UNDEF). I therefore propose to change array

Re: [PHP-DEV] More packed hash optimizations in array.c

2016-08-03 Thread Benjamin Coutu
Hello Xinchen, Thanks for changing array_pad and array_rand accordingly, that's very good. I noticed a small improvement we could make to array_slice for the packed case: We can change line 3003: if ((Z_ARRVAL_P(input)->u.flags & HASH_FLAG_PACKED) && !preserve_keys) => if ((Z_ARRVAL_P(input)->u.

[PHP-DEV] More packed hash optimizations in array.c

2016-07-28 Thread Benjamin Coutu
Hello Xinchen, I have noticed two more cases where we could easily use packed arrays. 1. array_merge($packed1, $packed2, ...): In the quite common case where all arguments are packed arrays, the resulting array can also be a packed array (as per documentation: "if the input arrays [...] contai

Re: [PHP-DEV] Optimizing array_reverse for packed hash tables (when preserve_keys=false)

2016-07-28 Thread Benjamin Coutu
Hi Xinchen, The code I used was simply derived from the code of the array_slice implementation (totally analogous). Maybe your suggested changes (check HASH_FLAG_PACKED fist + Z_TRY_ADDREF) should be carried over to array_slice then as well. Please go ahead and commit a patch, I'd prefer to sti

[PHP-DEV] Optimizing array_reverse for packed hash tables (when preserve_keys=false)

2016-07-27 Thread Benjamin Coutu
Hello Xinchen, Analogue to the array_slice implementation, the array_reverse function could also be optimized for packed hash tables when preserve_keys is false (most common). The following patch should do just that: if (!preserve_keys && (Z_ARRVAL_P(input)->u.flags & HASH_FLAG_PACKED)) {

[PHP-DEV] Inconsistent implementation of array sorting (old zend_qsort in array_multisort)

2016-06-23 Thread Benjamin Coutu
Hello everyone, While reviewing the array.c code base, I have noticed that the array_multisort function still uses the old zend_qsort instead of the new zend_sort algorithm that was introduced with PHP 7. That represents a clear inconsistency, because all other array sorting functions utilize

Re: [PHP-DEV] [VOTE] Scalar Type Hints

2015-02-09 Thread Benjamin Coutu
Hello everyone, (Un)fortunately I do not have voting rights, but here is my (freely expressed) 50 cents anyways: I appreciate that Andrea is trying to come up with a one-size-fits-all RFC. Nevertheless I believe it is flawed in regards to content as well as formally in terms of voting options.

Re: [PHP-DEV] Idea of optimizing php !empty(...) expression.

2015-02-07 Thread Benjamin Coutu
e, probably OpCache is not enabled or optimization flags are not properly set. Please see http://php.net/manual/en/book.opcache.php for more info. Cheers, Benjamin Coutu == Original == From: Oleg Serov To: internals@lists.php.net Date: Sun, 08 Feb 2015 00:13:05 +0100 Subject: [PHP-D

Re: [PHP-DEV] Re: Improvements to array.c code base

2015-02-01 Thread Benjamin Coutu
ly the way to go. Thanks, Ben == Original == From: Dmitry Stogov To: Benjamin Coutu Date: Mon, 02 Feb 2015 06:53:20 +0100 Subject: [PHP-DEV] Re: Improvements to array.c code base Hi Benjamin, We are in the state, when we mainly have to concentrate on big improvements that

Re: [PHP-DEV] [RFC] Fix "foreach" behavior

2015-01-30 Thread Benjamin Coutu
Hi Dmitry, Thank you for picking up on our proposal. RFC and patch look promising - awesome work! I am looking forward to it. Ben == Original == From: Dmitry Stogov To: PHP Internals Date: Fri, 30 Jan 2015 08:23:19 +0100 Subject: [PHP-DEV] [RFC] Fix "foreach" behavior Hi, I'

Re: [PHP-DEV] Improvements to for-each implementation

2015-01-22 Thread Benjamin Coutu
se it is only used for userland arrays, not other hash tables (such as object properties or internal structures that build upon the hashtable struct). Thanks, Ben == Original == From: Nikita Popov To: Benjamin Coutu Date: Thu, 22 Jan 2015 10:53:19 +0100 Subject: Re: [PH

Re: [PHP-DEV] Improvements to Hastable Bucket structure

2015-01-22 Thread Benjamin Coutu
CPU cache misses instead of one. yes, the patch is here: https://github.com/laruence/php-src/tree/union-hash-key thanks > > Thanks. Dmitry. > > On Thu, Jan 22, 2015 at 9:43 AM, Benjamin Coutu wrote: >> >> Hi, >> >> Currently a hashtable bucket has to store both, t

[PHP-DEV] Improvements to for-each implementation

2015-01-22 Thread Benjamin Coutu
, because they have their own pointer. This would effectively speed up most for-each operations and would have the extra benefit of not having to store an internal pointer in the hashtable structure. Please let me know your thoughts! Cheers, Ben -- Benjamin Coutu Zeyon Technologies

[PHP-DEV] Improvements to Hastable Bucket structure

2015-01-21 Thread Benjamin Coutu
tions to extract the correct meaning. Please let me know your thoughts! Cheers, Ben -- Benjamin Coutu Zeyon Technologies Inc. http://www.zeyos.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] Fixing strange foreach behavior.

2015-01-21 Thread Benjamin Coutu
Hi Dmitry, One could use an external pointer for the iteration and flag the hashtable while being iterated. In order to preserve the constraint that for-each is conceptually working on a copy, one would have to duplicate (zend_array_dup) the hastable everytime one alters it (e.g. adding/changi

Re: [PHP-DEV] Re: Improvements to array.c code base

2015-01-20 Thread Benjamin Coutu
Sorry, your right of course as not preserving keys only applies to numeric indices. == Original == From: Xinchen Hui To: Benjamin Coutu Date: Tue, 20 Jan 2015 10:13:04 +0100 Subject: Re: [PHP-DEV] Re: Improvements to array.c code base Hey: On Tue, Jan 20, 2015 at 5:06 PM

Re: [PHP-DEV] Re: Improvements to array.c code base

2015-01-20 Thread Benjamin Coutu
FAST_ZPP: Why is it not used more often, especially in the satndard libraries? Is there some particular drawback? I'd like to understand. Thanks, Ben == Original == From: Xinchen Hui To: Benjamin Coutu Date: Tue, 20 Jan 2015 09:53:38 +0100 Subject: [PHP-DEV] Re: Improvemen

[PHP-DEV] Improvements to array.c code base

2015-01-20 Thread Benjamin Coutu
ubiquitous! Giving it an opcode and making it part of the VM seams reasonable. Please let me know your thoughts. Cheers, Ben -- Benjamin Coutu Zeyon Technologies Inc. http://www.zeyos.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] [RFC] Combined Comparison (Spaceship) Operator

2015-01-19 Thread Benjamin Coutu
I wouldn't mind T_SPACESHIP, but T_THREEWAY_COMPARISON is probably more technically precise and better than T_COMBINED_COMPARISON. Cheers, Ben == Original == From: Jordi Boggiano To: Andrea Faulds Date: Mon, 19 Jan 2015 12:20:32 +0100 Subject: Re: [PHP-DEV] [RFC] Combined Comp

Re: [PHP-DEV] [RFC] Combined Comparison (Spaceship) Operator

2015-01-19 Thread Benjamin Coutu
This would be indeed very useful and also ideal from a sorting performance perspective! == Original == From: Andrea Faulds To: PHP internals Date: Mon, 19 Jan 2015 09:28:17 +0100 Subject: [PHP-DEV] [RFC] Combined Comparison (Spaceship) Operator Good morning, This is a reboot

Re: [PHP-DEV] Generating more efficient code for while-loop

2015-01-16 Thread Benjamin Coutu
== From: Dmitry Stogov To: Benjamin Coutu Date: Fri, 16 Jan 2015 17:12:34 +0100 Subject: Re: [PHP-DEV] Generating more efficient code for while-loop Hi Benjamin, Thanks for idea. With PHP7 AST compiler, it's quite easy to implement this (it took us 15 minutes to try :) However, it doesn&#x

[PHP-DEV] Generating more efficient code for while-loop

2015-01-15 Thread Benjamin Coutu
very excited! :) -- Benjamin Coutu Zeyon Technologies Inc. http://www.zeyos.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php