-
Notifications
You must be signed in to change notification settings - Fork 0
Notes on struct passing
-
PyPy's new cffi module uses libffi (also ffi of Pure and Haskell).
-
the main performance cost with libffi is generating the caller asm thunk, but this can be cached: https://github.com/tearsofphoenix/VeritasKit/issues/1
-
I didn't find any real benchmarks of libffi, but this seems to indicate the overhead is ~2-3x (ctypes and cffi both use libffi underneath) http://tungwaiyip.info/blog/2009/07/16/ctype_performance_benchmark
-
the types of situations where struct byval is necessary can probably afford the performance hit (?)
-
one other thing: LuaJIT FFI does not rely on libffi at all, and seems to do most of calling logic in about 2k lines: http://repo.or.cz/w/luajit-2.0.git/blob/master:/src/lj_ccall.c http://repo.or.cz/w/luajit-2.0.git/blob/master:/src/lj_cconv.c (it has good enough struct support to wrap both libLLVM and libclang: https://github.com/Neopallium/lua-clang-cindex https://github.com/grrrwaaa/luaclang ).
-
here is a simple example using libffi with LLVM: http://llvm.org/docs/doxygen/html/ExternalFunctions_8cpp_source.html
Docs:
http://llvm.org/docs/LangRef.html#structure-type
Useful threads:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-May/049404.html
http://llvm.1065342.n5.nabble.com/Passing-structures-by-value-on-Windows-td40439.html
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-May/049733.html
http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-October/043753.html