This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/54075] [4.7.1] unordered_map insert still slower than 4.6.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54075

Lawrence <tlawrence85 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tlawrence85 at gmail dot
                   |                            |com

--- Comment #36 from Lawrence <tlawrence85 at gmail dot com> 2012-11-05 22:12:12 UTC ---
It seems that this commit doesn't fully fix this issue. If you call rehash
multiple times with the same size, the second call to rehash resets
_M_prev_resize to a non-zero value in _M_next_bkt(). Here is a sample program
that shows this behavior:

#include <stdio.h>
#include <unordered_map>

int main(void) {
    std::unordered_map<int, int> myMap;

    myMap.rehash(4000000);
    myMap.rehash(4000000);

    unsigned long long buckets = myMap.bucket_count();
    int i = 0;
    while (i < 2000000000) {
        myMap.insert(std::make_pair(i, 0));
        ++i;
        if (buckets != myMap.bucket_count()) {
            printf("buckets %lu -> %lu\n", buckets, myMap.bucket_count());
            buckets = myMap.bucket_count();
        }
    }

    return 0;
}

(In reply to comment #13)
> Author: fdumont
> Date: Thu Jul 26 12:31:50 2012
> New Revision: 189889
> 
> URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189889
> Log:
> 2012-07-26  FranÃois Dumont  <fdumont@gcc.gnu.org>
> 
>     PR libstdc++/54075
>     * include/bits/hashtable.h
>     (_Hashtable<>::_Hashtable(_InputIterator, _InputIterator,
>     size_type, ...): Remove std::max usage to guarantee that hashtable
>     state is consistent with hash policy state.
>     (_Hashtable<>::rehash): Likewise. Set _M_prev_resize to 0 to avoid
>     the hashtable shrinking on next insertion.
>     * testsuite/23_containers/unordered_set/modifiers/reserve.cc: New.
>     * testsuite/23_containers/unordered_multiset/modifiers/reserve.cc: New.
>     * testsuite/23_containers/unordered_map/modifiers/reserve.cc: New.
>     * testsuite/23_containers/unordered_multimap/modifiers/reserve.cc: New.
> 
> Added:
>    
> branches/gcc-4_7-branch/libstdc++-v3/testsuite/23_containers/unordered_map/modifiers/reserve.cc
>    
> branches/gcc-4_7-branch/libstdc++-v3/testsuite/23_containers/unordered_multimap/modifiers/reserve.cc
>    
> branches/gcc-4_7-branch/libstdc++-v3/testsuite/23_containers/unordered_multiset/modifiers/reserve.cc
>    
> branches/gcc-4_7-branch/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/reserve.cc
> Modified:
>     branches/gcc-4_7-branch/libstdc++-v3/ChangeLog
>     branches/gcc-4_7-branch/libstdc++-v3/include/bits/hashtable.h


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]