https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57885

--- Comment #11 from François Dumont <fdumont at gcc dot gnu.org> ---
I just wanted to let you know about a way to enhance performance of your lookup
if you can afford it. I realized that if you copy the container before running
lookup you greatly enhance results. Here is what I obtain by just doing:

c1 = Container(c1);

between the 2 lookups:

Container:std::unordered_map<int,int>  Key:int
Insertion: 16407 8818 7952 7881 7874  min=7874 max=16407
Lookup1:   15774 15767 15985 15845 15751  min=15751 max=15985
Lookup2:   13613 12725 12685 12678 12861  min=12678 max=13613

Container:std::tr1::unordered_map<int,int>  Key:int
Insertion: 22044 5845 5716 5785 5608  min=5608 max=22044
Lookup1:   12620 12881 12597 12568 12656  min=12568 max=12881
Lookup2:   14385 12506 12043 13122 11970  min=11970 max=14385

You see that lookup 2 is much closer to the tr1 implementation. This is so
because after copy the container has a much better memory localization so less
memory page fault. If allocator keeps on returning memory node adjacent to each
other you end up with all nodes relying in the same memory block.

I have plan to document this. Of course you can only use it if you initialize
once for all or you barely update the content but lookup into it very often.

I am still looking at solutions to restore previous lookup performances.

Reply via email to