[Haskell-cafe] Takusen sqlite3 insert is very slow

Vasyl Pasternak vasyl.pasternak at gmail.com
Sat Mar 20 06:32:44 EDT 2010

Hi Cafe,

I have another problem, please look at code:

storeInDb = withSession (connect "test.db")
                 execDDL (sql "create table x (y int)")
                 forM_ ([1..10000] :: [Int])
                   (\x -> do
                       execDML (cmdbind ("insert into x (y) values (?);")
                                [bindP x])
                       return ()))

This code runs 16 seconds which is very slow for this simple task. RTS
output is below. After profiling this program I found that 85% of its
time it spends in  'Database.Sqlite.SqliteFunctions.stmtFetch'.
Currently I don't know how to make it faster, maybe anyone had this
problem later?

HDBC inserts very fast, so this is not sqlite error.

RTS output:

     156,195,264 bytes allocated in the heap
         591,280 bytes copied during GC
           3,952 bytes maximum residency (1 sample(s))
          10,968 bytes maximum slop
               1 MB total memory in use (0 MB lost due to fragmentation)

  Generation 0:   295 collections,     0 parallel,  0.00s,  0.01s elapsed
  Generation 1:     1 collections,     0 parallel,  0.00s,  0.02s elapsed

  INIT  time    0.00s  (  0.03s elapsed)
  MUT   time    0.87s  ( 16.09s elapsed)
  GC    time    0.00s  (  0.02s elapsed)
  RP    time    0.00s  (  0.00s elapsed)
  PROF  time    0.00s  (  0.00s elapsed)
  EXIT  time    0.00s  (  0.00s elapsed)
  Total time    0.88s  ( 16.14s elapsed)

  %GC time       0.5%  (0.1% elapsed)

  Alloc rate    179,111,917 bytes per MUT second

  Productivity  99.5% of total user, 5.4% of total elapsed


More information about the Haskell-Cafe mailing list