From:             
Operating system: 
PHP version:      trunk-SVN-2011-01-28 (SVN)
Package:          Arrays related
Bug Type:         Feature/Change Request
Bug description:Zend engine's hashtable performance tweaks

Description:
------------
What was done:

- Hash function in zend_hash.h was rebuilt and became much faster, without
losing the most important properties.

- Hashtable implementation was changed from Simple chaining to Open
addressing with linear probing, but with linked bucket, not included in
hash array, which causes:

-- Bucket structure to lose 2 pointers.

-- Searching works similar, but don't have to jump with pointers stored in
different memory locations, inserting, deleting and rehashing don't need to
update linked list, but must search for first empty bucket, which is fast,
because it scans continuous memory.

-- Load factor decreases from 1.0 to 0.5-0.75 to make less collisions and
faster hashtable, which in turn increases memory footprint a little.

- Open addressing doesn't change significantly performance, but next thing
was to create new array (arEmpty), which is of size nTableSize bytes, which
keeps track of used/empty buckets and makes inserting and rehashing much
faster. In future it can be tested as bit-array with size of nTableSize/8
bytes.

- More macros were added to replace repetitive constructs.

- New constants were added to allow:

-- Creating new hashtables of size at least X (where 4 and 8 are
reasonable), which makes no rehashing and reallocing memory while changing
size to 2 and then to 4.

-- For small tables it's better to extend them by a factor of 4 times, not
2, to make rehashing cost smaller for most hashtables, of cost of little
higher memory consumption.

-- For large tables it's better to have other load factor, closer to 1,
while for small tables it's better to use load factor closer to 0.5.



What should be done:

-
http://lxr.php.net/xref/PHP_TRUNK/ext/standard/html_tables/html_table_gen.php#722
should be changed and html_tables.h regenerated, but this will need to
rewrite hashtable engine from C to PHP

- APC should be fixed



What can be done:

- Make new constants configurable by php.ini.

- Test if changing arEmpty from byte-array to bit-array helps on
performance.

- Tweak default constants' values using some real-live benchmarks.

- Prove (or modify and prove) hash function to have property, that it has
no collisions if two keys don't differ on no more than 6 bytes, which will
lead to memcmp omit first (or last) 6 bytes of key. Also simpler thing may
be proven, that is it has no collisions if two keys are not longer than 6
bytes, which will make most string keys omit memcpy at all.


-- 
Edit bug report at http://bugs.php.net/bug.php?id=53866&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=53866&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=53866&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=53866&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=53866&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=53866&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=53866&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=53866&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=53866&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=53866&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=53866&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=53866&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=53866&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=53866&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=53866&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53866&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53866&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=53866&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=53866&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=53866&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=53866&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=53866&r=mysqlcfg

Reply via email to