# zend_inline_hash_function reimplementation

- Thread: https://externals.io/message/39129
- Original archive: https://news-web.php.net/php.internals/39129
- Started by Michal Dziemianko on 2008-07-21T15:29:26+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #39129 — Michal Dziemianko — 2008-07-21T15:29:26+00:00

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

Hello,
I have looked into Zend/zend_hash.h and I guess it might be sped up a  
little. So far it uses D. Bernstein's hash which is quite fast, but I  
think it might be worth replacing it with MurmurHash. I have tried  
comparison of speed for them (both as separate C programs, and  
compiled into PHP 5_3). Results for REAL keys (collected on running  
web server) are at the bottom of this page: http://212.85.117.53/gsoc/ 
index.php?option=com_content&view=article&id=65:hash-functions-for- 
hash-tables&catid=34:profiling&Itemid=54

Murmur is Public Domain, and its author is maintaining it all the  
time so I guess it will be faster and better. There is comparison of  
distribution at both the page I gave and here: http:// 
murmurhash.googlepages.com/

The patch for 5_3 (applicable to HEAD) as attachment

---

## #39130 — Lukas Kahwe Smith — 2008-07-21T15:38:13+00:00

URL: https://externals.io/message/39129#39130 · In reply to: #39129

> Hello,
> I have looked into Zend/zend_hash.h and I guess it might be sped up  
> a little. So far it uses D. Bernstein's hash which is quite fast,  
> but I think it might be worth replacing it with MurmurHash. I have  
> tried comparison of speed for them (both as separate C programs, and  
> compiled into PHP 5_3). Results for REAL keys (collected on running  
> web server) are at the bottom of this page: http://212.85.117.53/gsoc/index.php?option=com_content&view=article&id=65:hash-functions-for-hash-tables&catid=34:profiling&Itemid=54


speeding up array's does indeed look like a place where one could give  
a nice boost to many php applications. however it is also a place that  
could create such as many problems of course. so getting this into 5.3  
seems a bit unlikely at this point given that the feature freeze is  
planned for the 24th.

that being said, on the page i only see benchmarks with artificial  
data/code. did you also run some benchmarks again some popular php  
applications so see what the real world benefits are in terms of  
requests per second?

regards,
Lukas Kahwe Smith
mls@pooteeweet.org

---

## #39135 — Andi Gutmans — 2008-07-21T18:01:38+00:00

URL: https://externals.io/message/39129#39135 · In reply to: #39129

Hi Michal,

Can you please send a link to the patch so we can review? I didn't get
the attachment.

Thanks,
Andi




> -----Original Message-----
> From: Michal Dziemianko [mailto:michal.dziemianko@gmail.com]
> Sent: Monday, July 21, 2008 8:29 AM
> To: internals@lists.php.net
> Subject: [PHP-DEV] zend_inline_hash_function reimplementation
> 
> Hello,
> I have looked into Zend/zend_hash.h and I guess it might be sped up a
little.
> So far it uses D. Bernstein's hash which is quite fast, but I think it
might
> be worth replacing it with MurmurHash. I have tried comparison of
speed for
> them (both as separate C programs, and compiled into PHP 5_3). Results
for
> REAL keys (collected on running web server) are at the bottom of this
page:
> http://212.85.117.53/gsoc/
> index.php?option=com_content&view=article&id=65:hash-functions-for-
> hash-tables&catid=34:profiling&Itemid=54
> 
> Murmur is Public Domain, and its author is maintaining it all the time
so I
> guess it will be faster and better. There is comparison of
distribution at
> both the page I gave and here: http:// murmurhash.googlepages.com/
> 
> The patch for 5_3 (applicable to HEAD) as attachment

---

## #39137 — Scott MacVicar — 2008-07-21T18:14:36+00:00

URL: https://externals.io/message/39129#39137 · In reply to: #39135

Hi Andi,

The patch is attached for 5_3.

I've got some time allocated tomorrow to review all of Michal's patches 
that have been produced for the GSoC. I'll try to post some figures from 
real life apps.

Scott
Andi Gutmans wrote:
> Hi Michal,
> 
> Can you please send a link to the patch so we can review? I didn't get
> the attachment.
> 
> Thanks,
> Andi
> 
> 
> 
> 
> > […]
> little.
> > […]
> might
> > […]
> speed for
> > […]
> for
> > […]
> page:
> > […]
> so I
> > […]
> distribution at
> > […]

---

## #39139 — Andi Gutmans — 2008-07-21T18:56:56+00:00

URL: https://externals.io/message/39129#39139 · In reply to: #39137

Thanks. Is there also a 64bit variant of this algorithm? That could
deliver a substantial benefit.

Andi

> -----Original Message-----
> From: Scott MacVicar [mailto:scott@macvicar.net]
> Sent: Monday, July 21, 2008 11:15 AM
> To: Andi Gutmans
> Cc: Michal Dziemianko; internals@lists.php.net
> Subject: Re: [PHP-DEV] zend_inline_hash_function reimplementation
> 
> Hi Andi,
> 
> The patch is attached for 5_3.
> 
> I've got some time allocated tomorrow to review all of Michal's
patches that
> have been produced for the GSoC. I'll try to post some figures from
real life
> apps.
> 
> Scott
> Andi Gutmans wrote:
> > […]
get
> > […]
a
> > […]
this
> > […]

---

## #39149 — Stanislav Malyshev — 2008-07-21T20:58:28+00:00

URL: https://externals.io/message/39129#39149 · In reply to: #39137

Hi!

I understand this patch has potential portability issues for 
architectures that won't be able to read int's unaligned.

Maybe we could keep both of them and do some configure test to see if it 
works fine, if not - use the old one?

Also I understand that this function returns uint while old hash 
returned ulong. What happens with that on 64-bit platforms?
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #39153 — Scott MacVicar — 2008-07-21T21:24:12+00:00

URL: https://externals.io/message/39129#39153 · In reply to: #39149

There is an aligned version of the algorithm available but its slower,  
there is also a 64-bit version in the works. I emailed the author  
about its progress to check.

At the moment adding both looks the way forward, i'll benchmark a PPC  
version of the algorithm shortly.

Scott


> Hi!
>
> I understand this patch has potential portability issues for  
> architectures that won't be able to read int's unaligned.
>
> Maybe we could keep both of them and do some configure test to see  
> if it works fine, if not - use the old one?
>
> Also I understand that this function returns uint while old hash  
> returned ulong. What happens with that on 64-bit platforms?
> -- 
> Stanislav Malyshev, Zend Software Architect
> stas@zend.com   http://www.zend.com/
> (408)253-8829   MSN: stas@zend.com
