New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load constants from data segment #2618

scoder opened this Issue Sep 21, 2018 · 0 comments


None yet
1 participant

scoder commented Sep 21, 2018

Currently, Cython generates code to create constants (strings, tuples, code objects, …) at module init time, using C-API calls. As an experimental patch by Facebook shows, the entire objects could be statically allocated and loaded from the C data segment instead. The resulting C code shows a nice example of code that Cython could generate as well.


  • We need to keep the dynamic object creation, both as a fallback and to support PyPy.
  • This requires some adaptations across CPython versions, especially for Unicode strings. For that, we need to generate copies of the object structs and select them at C compile time via PY_HEX_VERSION.
  • In the easiest case, we could limit it to Py3.4+ for the beginning, as most object differences are between Py2 and Py3, so this would reduce the duplication.
  • It's unclear what to do about small integers and interned strings, since loading them from the data segment would prevent them from being singletons.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment