From: spinutids@... Date: 2016-09-05T01:09:03+00:00 Subject: [ruby-core:77149] [Ruby trunk Feature#12142] Hash tables with open addressing Issue #12142 has been updated by Satoru Horie. Hello, everyone. I want to help to merge these excellent results into trunk. I���m now reviewing both codes, and trying to consider other benchmarks to provide more solid evidence toward merge and to compare three implementations. Firstly, Clang reports errors. (It seems to be caused by -Wshorten-64-to-32) I sent PRs to both repos. I run benchmarks on my environment. The result are following. * Environment OSX10.11.6, 1.1GHz Intel Core m3 Apple LLVM version 7.3.0 (clang-703.0.31) Target: x86_64-apple-darwin15.6.0 * Command (borrowed from https://github.com/vnmakarov/ruby/README.md) ruby ../research/ht/funny_falcon_array2/benchmark/driver.rb -p hash -r 3 -e ./miniruby -e ../research/ht/funny_falcon_array2/miniruby -e ../research/ht/vlad_ruby/miniruby | awk 'NF==3 && /hash/ {s+=$2;s2+=$3;n++;print} END{print s/n, s2/n}' * Targets funny falcon's : e38ae901c443370186b57f5b88359f15d25974a0 + fix compilation error (brench st_table_with_array2) Vladimir's: 314c25696cc97a9e44c93f95c6f30b1ba9f52252 + fix compilation error (branch hash_table_with_open_addressing) trunk: e5c6454efa01aaeddf4bc59a5f32d5f1b872d5ec ```` bighash 1.408 1.145 hash_aref_dsym 0.996 0.969 hash_aref_dsym_long 1.914 1.894 hash_aref_fix 1.013 1.007 hash_aref_flo 1.628 1.725 hash_aref_miss 0.919 1.010 hash_aref_str 1.061 1.292 hash_aref_sym 1.023 0.983 hash_aref_sym_long 1.111 1.061 hash_flatten 1.097 1.071 hash_ident_flo 0.965 0.941 hash_ident_num 0.936 0.940 hash_ident_obj 0.918 0.923 hash_ident_str 0.900 0.912 hash_ident_sym 0.991 0.958 hash_keys 1.780 1.744 hash_long 1.194 1.532 hash_shift 1.758 1.670 hash_shift_u16 1.760 1.634 hash_shift_u24 1.818 1.692 hash_shift_u32 1.823 1.670 hash_small2 1.182 1.049 hash_small4 1.124 1.010 hash_small8 1.832 1.999 hash_to_proc 0.984 1.008 hash_values 1.780 1.825 vm2_bighash 4.304 5.667 1.41552 1.4567 ```` I may ask some questions on implementations and on a requirement of other benchmarks after my reviewing. ---------------------------------------- Feature #12142: Hash tables with open addressing https://bugs.ruby-lang.org/issues/12142#change-60364 * Author: Vladimir Makarov * Status: Open * Priority: Normal * Assignee: ---------------------------------------- ~~~ Hello, the following patch contains a new implementation of hash tables (major files st.c and include/ruby/st.h). Modern processors have several levels of cache. Usually,the CPU reads one or a few lines of the cache from memory (or another level of cache). So CPU is much faster at reading data stored close to each other. The current implementation of Ruby hash tables does not fit well to modern processor cache organization, which requires better data locality for faster program speed. The new hash table implementation achieves a better data locality mainly by o switching to open addressing hash tables for access by keys. Removing hash collision lists lets us avoid *pointer chasing*, a common problem that produces bad data locality. I see a tendency to move from chaining hash tables to open addressing hash tables due to their better fit to modern CPU memory organizations. CPython recently made such switch (https://hg.python.org/cpython/file/ff1938d12240/Objects/dictobject.c). PHP did this a bit earlier https://nikic.github.io/2014/12/22/PHPs-new-hashtable-implementation.html. GCC has widely-used such hash tables (https://gcc.gnu.org/svn/gcc/trunk/libiberty/hashtab.c) internally for more than 15 years. o removing doubly linked lists and putting the elements into an array for accessing to elements by their inclusion order. That also removes pointer chaising on the doubly linked lists used for traversing elements by their inclusion order. A more detailed description of the proposed implementation can be found in the top comment of the file st.c. The new implementation was benchmarked on 21 MRI hash table benchmarks for two most widely used targets x86-64 (Intel 4.2GHz i7-4790K) and ARM (Exynos 5410 - 1.6GHz Cortex-A15): make benchmark-each ITEM=bm_hash OPTS='-r 3 -v' COMPARE_RUBY='' Here the results for x86-64: hash_aref_dsym 1.094 hash_aref_dsym_long 1.383 hash_aref_fix 1.048 hash_aref_flo 1.860 hash_aref_miss 1.107 hash_aref_str 1.107 hash_aref_sym 1.191 hash_aref_sym_long 1.113 hash_flatten 1.258 hash_ident_flo 1.627 hash_ident_num 1.045 hash_ident_obj 1.143 hash_ident_str 1.127 hash_ident_sym 1.152 hash_keys 2.714 hash_shift 2.209 hash_shift_u16 1.442 hash_shift_u24 1.413 hash_shift_u32 1.396 hash_to_proc 2.831 hash_values 2.701 The average performance improvement is more 50%. ARM results are analogous -- no any benchmark performance degradation and about the same average improvement. The patch can be seen as https://github.com/vnmakarov/ruby/compare/trunk...hash_tables_with_open_addressing.patch or in a less convenient way as pull request changes https://github.com/ruby/ruby/pull/1264/files This is my first patch for MRI and may be my proposal and implementation have pitfalls. But I am keen to learn and work on inclusion of this code into MRI. ~~~ ---Files-------------------------------- 0001-st.c-change-st_table-implementation.patch (59.4 KB) st-march31.patch (114 KB) base.patch (93.8 KB) hash.patch (4.48 KB) strong_hash.patch (8.08 KB) city.patch (19.4 KB) new-hash-table-benchmarks.patch (1.34 KB) hash_improvements_and_st_implementation_changes.mbox (101 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: