-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cuckoo loses data when inserting 65th element via mutate #55
Comments
Here's a much smaller example: module Main where
import Control.Monad (forM_)
import Control.Monad.ST
import Data.Char
import qualified Data.HashTable.ST.Cuckoo as Cuckoo
import qualified Data.Set as Set
main :: IO ()
main = do
let orig = [0..64] :: [Int]
let orig' = Set.fromList orig
print $ length orig'
final <- do
temp <- stToIO Cuckoo.new
--works fine:
--forM_ orig $ \k -> stToIO $ Cuckoo.insert temp k ()
forM_ orig $ \k -> stToIO $ Cuckoo.mutate temp k (const (Just (), ()))
stToIO $ Cuckoo.foldM (fmap pure <$> flip (:)) [] temp
let final' = Set.fromList $ fmap fst final
print $ length final'
putStrLn "diff:"
print $ Set.difference orig' final'
print $ Set.difference final' orig' The problem is with |
If you change 0..64 to 0..200000 even more data is lost:
|
@vbsd you wrote that function, can you take a look? This bug only happens if the hashtable has 64 elements and you insert a new one using |
@infinity0 I’m afraid there’s no way I can get to a computer until the next Monday or so. I’ll try to have a look then. |
@vbsd any update? |
@gregorycollins @vbsd ping :) |
Just slammed headfirst into this, and lost several hours not believing what my code was telling me. Any update? |
I am a co-maintainer. I will look at this on the weekend. |
This is a modified version of the test which:
It is this last operation which fails.
|
If I add another test function like this:
and run it as |
I have some clues. The The problem occurs in the |
Spent a little more time on this. |
Haven't had a chance to get back to this. I narrowed the problem down, but got bogged down trying to figure out what was going on. I may not get back to looking at this further. If anyone is interested in pursuing this they should contact me and I can push my debug branch and document the debugging I have done a bit better. |
This is still not fixed. Could someone at least push a hackage update adding some big warnings to the package documentation? It looks like several people have lots hours of debugging over this, myself included, and I'd guess more people that haven't commented. There exists a good fast alternative - |
FWIW, |
I am not sure about the use-case context of these performance issues you mention. If I remember right, we tested it for an internal company use-case last year, and it was actually faster than this package. Though our use-case was a network-IO-bound program with a few thousand entries max in this map, as opposed to a CPU-bound program using lots of memory. |
That's good to hear! I think the main concern with using |
Ah, I finally found http://hackage.haskell.org/package/hashable-1.3.0.0/docs/Data-Hashable.html#g:1 Apologies for all the noise. I'll stop now! :) |
Ah right. That's a general thing common to all hashtables in any language. The other tickets you linked seemed to be talking about different issues, though? I never actually thought about this in the context of pure Haskell, but since For |
@infinity0 I've brought this up in haskell-unordered-containers/unordered-containers#265. You're welcome to chime in! :) |
I don't think the |
Fix #55 (mutate is broken when growing the table)
@gregorycollins Nice! Would you like me to make a release? |
I pushed two already (1.2.4.0 to fix the bug and 1.2.4.1 just now to fix some bad deps that got in -- sloppy Greg no cookie) |
I have to say, that fix makes me highly suspicious of everything else that was changed in 196fa53 |
You're not wrong and clearly we didn't review it carefully enough -- or insist on a high enough test coverage at the time. Should we just take it out of the API until we have time to fix it? |
edit: see next comment for a much better and more minimal reproduction:
The text was updated successfully, but these errors were encountered: