Bill Roper (billroper) wrote,
Bill Roper

Not As Fast As You Intimated

When I ported all of our C++ code over to Java, one of the things I was told was "You don't have to worry about the speed of looking things up in hash maps. They're really fast." And since maintaining shared references to a single copy of an object was a pain in the butt, I started storing keys to the objects and looking them up in a master hash map for each of the different types of objects.

Then I found out that I was spending too much time looking up some of the things in the hash maps. So I made sure that the keys for the most frequently accessed object were immutable and shared via a common cache. And then I stored the pre-computed hash code inside the key, because not having to hash the key every time would speed up the searches a lot.

But the C++ code was running too slow, as I'd replaced the old shared pointers there. So I did the same trick in C++ that I done with the shared immutable cached keys with the pre-computed hash codes. Still not fast enough though.

Well, there was this value that I had previously pre-computed and stored, but was now looking up on the fly in a hash map with potentially multiple checks per value. Let's try putting that stored value back and only updating it when it needs to be updated.

Yes, that is fast enough.

Tags: c++, computers, java, musings, work

  • Paying It Off

    I checked tonight and I do indeed have two more months to pay my property tax without incurring late fees. So I guess I'll be paying that later. The…

  • Jean, Jean

    I am trying to buy a new pair of jeans. Normally, this would be simple. Go to Amazon and order a pair of Levi's 560s in my size. Except that Levi has…

  • Ice, Ice, Baby

    Much of today could have been sold for scrap, but there was some progress on the refrigerator front. After decanting the contents of the fridge and…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded