1. Python CFFI
  2. Untitled project
  3. cffi
  4. Issues
Issue #66 closed

many calls to cdef() is much much slower than few calls to cdef()

Jean-Paul Calderone
created an issue

I noticed that when I changed opentls's use of cffi from calling cdef once per type definition and prototype (ie, from many hundreds or perhaps even a thousand calls) to a single call containing all the same definitions and prototypes, import time went from about 48 seconds to about 0.7 seconds.

I suggest documenting that the preferred usage is to call cdef few times with lots of definitions rather than many times with few definitions. Or making it faster to call it many times.

Comments (1)

  1. Armin Rigo

    This is outdated by ffi.set_source(), with which you normally don't call ffi.cdef() at all at runtime. If you have many calls to cdef() in the build script, too bad, the build script will take half a second longer to run. Of course this argument doesn't apply to non-set_source() models, but I am still closing this issue because using a non-set_source() approach for a very big library seems like a bad idea IMHO.

  2. Log in to comment