Req #50486 [Asn->Csd]: [PATCH] optimization for safe_address on exotic platforms
| From: | nikic@php.net | Date: | Wed, 04 Mar 2020 14:45:17 +0000 |
| Subject: | Req #50486 [Asn->Csd]: [PATCH] optimization for safe_address on exotic platforms | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225884@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=50486&edit=1
ID: 50486
Updated by: nikic@php.net
Reported by: basant dot kukreja at gmail dot com
Summary: [PATCH] optimization for safe_address on exotic
platforms
-Status: Assigned
+Status: Closed
Type: Feature/Change Request
Package: Performance problem
Operating System: Solaris 10
PHP Version: 5.3SVN-2009-12-16 (SVN)
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
I believe this is no longer relevant, as the zend_multiply() code uses __builtin_smulll_overflow()
nowadays.
Previous Comments:
------------------------------------------------------------------------
[2016-08-06 02:37:55] kalle@php.net
Dmitry, any input on this?
------------------------------------------------------------------------
[2009-12-16 01:35:09] basantk@php.net
On a ecommerce benchmark on Solaris sparc, new implementation reduced the time spent in _ecalloc to
50%.
------------------------------------------------------------------------
[2009-12-16 01:34:07] basantk@php.net
Microbenchmark testing on Linux x86_64 :
=======================================
Based on the above suggested implementation, I benchmarked 3 implementation of
safe_address on Linux x86_64 (fedora 11) using a micro benchmark. Here are the
results :
--------------------------------------
For a regular nmemb * size + offset when no overflow possible :
nmemb = 23456 size = 67890 offset = 12345
assembly version of safe_address time diff = 26 ticks
doubles imlementation of safe_address time diff = 72 ticks
proposed safe_address time diff = 30 ticks
--------------------------------------
For bigger integer multiplication :
nmemb = 2589934591 size = 4294967295 offset = 5
assembly version of safe_address time diff = 26 ticks
doubles imlementation of safe_address time diff = 75 ticks
proposed safe_address time diff = 76 ticks
--------------------------------------
Here is the micro benchmark link :
http://bitbucket.org/basantk/php53perfpatches/src/tip/safe_address_bench.c
------------------------------------------------------------------------
[2009-12-16 01:33:06] basantk@php.net
Here is the link to the proposed patch :
http://bitbucket.org/basantk/php53perfpatches/raw/ca263ffd272b/safe_address_64bitopt_php53.txt
Richard Smith did the original work and I refined the patch.
In this proposed optimization we can check if the inputs are
sufficiently large enough so that overflow is possible. If overflow is
possible, regular double logic will follow.
Link the the mail sent to internals mailing list :
http://marc.info/?l=php-internals&m=126084384813237&w=2
------------------------------------------------------------------------
[2009-12-16 01:30:34] basant dot kukreja at gmail dot com
Description:
------------
safe_address function calculates nmemb * size + offset and it want to make
sure that it output doesn't overflow.
It uses doubles for finding overflow which is very inefficent for platforms
like sparc.
Reproduce code:
---------------
Any Php script causes _ecalloc function.
Expected result:
----------------
Good performance on platform other than gcc + x86_64 combo.
Actual result:
--------------
Poor _ecalloc performance on plaforms like Solaris.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=50486&edit=1