IreneKnapp/direct-sqlite — pull request #20 by nurpax (2012-12-18 17:29:24+00:00)
Title: Optimize FFI: Use unsafe FFI calling convention for column data accessors

FFI calling convention for C functions defaults to 'safe' which incurs
a heavy per-call overhead. Use of 'unsafe' should be fine for the
column data accessors as they do not callback to Haskell from C.
Furthermore, no I/O should be happening in these accessors, all these
functions do is move data over from C land to Haskell.

Performance delta in a synthetic benchmark such as
https://github.com/nurpax/db-bench is big -- almost 3x. The simplest
benchmark case speeds up from 2.4M rows/sec to 7.2M rows/sec. The
nice thing about this is that direct-sqlite now also beats Python
sqlite3 module by a factor of 2.8x whereas before they were about the
same speed.