Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 870445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:28:37+00:00 2026-05-15T10:28:37+00:00

I read that hash tables in Haskell had performance issues (on the Haskell-Cafe in

  • 0

I read that hash tables in Haskell had performance issues (on the Haskell-Cafe in 2006 and Flying Frog Consultancy’s blog in 2009), and since I like Haskell it worried me.

That was a year ago, what is the status now (June 2010)? Has the “hash table problem” been fixed in GHC?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:28:38+00:00Added an answer on May 15, 2026 at 10:28 am

    The problem was that the garbage collector is required to traverse mutable arrays of pointers (“boxed arrays”) looking for pointers to data that might be ready to deallocate. Boxed, mutable arrays are the main mechanism for implementing a hashtable, so that particular structure showed up the GC traversal issue. This is common to many languages. The symptom is excessive garbage collection (up to 95% of time spent in GC).

    The fix was to implement “card marking” in the GC for mutable arrays of pointers, which occured in late 2009. You shouldn’t see excessive GC when using mutable arrays of pointers in Haskell now. On the simple benchmarks, hashtable insertion for large hashes improved by 10x.

    Note that the GC walking issue doesn’t affect purely functional structures, nor unboxed arrays (like most data parallel arrays, or vector-like arrays, in Haskell. Nor does it affect hashtables stored on the C heap (like judy). Meaning that it didn’t affect day-to-day Haskellers not using imperative hash tables.

    If you are using hashtables in Haskell, you shouldn’t observe any issue now. Here, for example, is a simple hashtable program that inserts 10 million ints into a hash. I’ll do the benchmarking, since the original citation doesn’t present any code or benchmarks.

    import Control.Monad
    import qualified Data.HashTable as H
    import System.Environment
    
    main = do
      [size] <- fmap (fmap read) getArgs
      m <- H.new (==) H.hashInt
      forM_ [1..size] $ \n -> H.insert m n n
      v <- H.lookup m 100
      print v
    

    With GHC 6.10.2, before the fix, inserting 10M ints:

    $ time ./A 10000000 +RTS -s
    ...
    47s.
    

    With GHC 6.13, after the fix:

    ./A 10000000 +RTS -s 
    ...
    8s
    

    Increasing the default heap area:

    ./A +RTS -s -A2G
    ...
    2.3s
    

    Avoiding hashtables and using an IntMap:

    import Control.Monad
    import Data.List
    import qualified Data.IntMap as I
    import System.Environment
    
    main = do
      [size] <- fmap (fmap read) getArgs
      let k = foldl' (\m n -> I.insert n n m) I.empty [1..size]
      print $ I.lookup 100 k
    

    And we get:

    $ time ./A 10000000 +RTS -s        
    ./A 10000000 +RTS -s
    6s
    

    Or, alternatively, using a judy array (which is a Haskell wrapper calling C code through the foreign-function interface):

    import Control.Monad
    import Data.List
    import System.Environment
    import qualified Data.Judy as J
    
    main = do
      [size] <- fmap (fmap read) getArgs
      j <- J.new :: IO (J.JudyL Int)
      forM_ [1..size] $ \n -> J.insert (fromIntegral n) n j
      print =<< J.lookup 100 j
    

    Running this,

    $ time ./A 10000000 +RTS -s
    ...
    2.1s
    

    So, as you can see, the GC issue with hashtables is fixed, and there have always been other libraries and data structures which were perfectly suitable. In summary, this is a non-issue.

    Note: as of 2013, you should probably just use the hashtables package, which supports a range of mutable hashtables natively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read that you could call JavaScript code from a Java Applet by calling
I read that Domain Driven Design is about concentrating on the problem domain instead
I read that SQL exceptions are treated as normal exceptions in managed SPs; I
I read that you should define your JavaScript functions in the <head> tag, but
I've read that Lambda Expressions are an incredibly powerful addition to C#, yet I
I once read that one way to obtain a unique filename in a shell
I have read that using database keys in a URL is a bad thing
After having read that QuickSilver was no longer supported by BlackTree and has since
I've read that compound primary keys will confuse the hell out of typical ORM
I've read that Silverlight 2.0 imposes by design an asynchronous model when communicating with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.