Skip to content
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

split mutable and immutable parts of code objects #102802

Open
carljm opened this issue Mar 18, 2023 · 3 comments
Open

split mutable and immutable parts of code objects #102802

carljm opened this issue Mar 18, 2023 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@carljm
Copy link
Member

carljm commented Mar 18, 2023

Code objects are mostly immutable, but have some mutable parts: co_code_adaptive, co_extra, _co_cached, and co_filename (I think this is all on first glance, may have missed something.)

It would be useful to split the immutable and mutable parts of the code object, so as to be able to maximize sharing; see discussion in faster-cpython/ideas#466

The mutable part should have a pointer to the immutable part, rather than the other way around; this leaves open the possibility of sharing the immutable part between sub-interpreters.

@carljm carljm added type-feature A feature request or enhancement performance Performance or resource usage and removed type-feature A feature request or enhancement labels Mar 18, 2023
@carljm
Copy link
Member Author

carljm commented Mar 18, 2023

Doing #101346 might also help to simplify this a bit.

@iritkatriel
Copy link
Member

Why is filename mutable?

@carljm
Copy link
Member Author

carljm commented Mar 18, 2023

Why is filename mutable?

Because a precompiled pyc file may be imported from a different file system location than where it was originally compiled, so on import we fix up co_filename to match the imported-from location; see the call to _imp._fix_co_filename in importlib.

This falls into the category of "idempotent constant" since it is only set once at import time and then should remain immutable thereafter. (EDIT: or maybe not? it is technically mutable at Python level, not just C level.) In any case, from the perspective of deep freezing it has to be considered mutable.

@iritkatriel iritkatriel added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
Projects
None yet
Development

No branches or pull requests

2 participants