1. Python CFFI
  2. Untitled project
  3. cffi
  4. Issues
Issue #26 resolved

Cache the cdef types inside the .so made by verify()

Armin Rigo
created an issue

Parsing the C code of large cdef()s takes time. We should accept lazily the strings passed to the cdef()s. When verify() is called, if a module was already compiled, then the compiled module should contain everything needed --- e.g. a marshal-like description of backend types. This would avoid both the C parsing and (with some care) the building of model.py instances.

Comments (5)

  1. Simon Sapin

    I don’t know if this is the same or a separate issue, but I would also like to cache the result of calling ffi.cdef() when using dlopen() instead of verify().

    Currently, cdef() adds 200ms to the import time of cairocffi on my laptop.

  2. Armin Rigo reporter

    Simon Sapin: it's related, but the same solution would not work. The problem is that in the dlopen() approach we don't generate any file at all, so we don't have an obvious place to store the cache. Moreover, by now the solution we want to implement seems to be rather explicit recompilation instead of implicit automatic caching, which means that dlopen() is going to be even more marginalized.

  3. Simon Sapin

    I’m fine to explicitly "compiling" the C declarations into something that can be loaded more quickly (possibly stored with pickle?)

    Regarding dlopen() vs. verify(), the point is that not having a C compiler involved makes everything much easier. I can tell Windows users to get a pre-compiled CFFI, just distribute source packages and have them work everywhere.

  4. Log in to comment