On Thu, 2010-01-21 at 23:42 +0100, "Martin v. Löwis" wrote:
> > With my "downstream distributor of Python" hat on, I'm wondering if it
> > would be feasible to replace the current precompiled .pyc/.pyo files in
> > marshal format with .so/.dll files in platform-specific shared-library
> > format, so that the pre-compiled versions of the stdlib could be
> > memory-mapped and shared between all Python processes on a system.
>
> I don't think replacing the byte code will be feasible, at least not
> without breaking compatibility (else f.func_code.co_code would stop
> working).
co_code would remain a PyObject* referencing a PyBytesObject instance.
> I also think you are overestimating the potential for sharing: much
> of what lives in pyc files are actual Python objects, which need to
> be reference-counted; doing this in a shared fashion is not feasible.
>
The struct PyObject instances themselves wouldn't be shared; my idea
(for 2.*) was to introduce a new ob_sstate value into PyStringObject
indicating a pointer into a shared memory area, so that this large
immutable data can be shared; something like this:
typedef struct {
PyObject_VAR_HEAD
long ob_shash;
int ob_sstate;
union {
char ob_sval[1];
char *ob_sdata;
};
...
} PyStringObject;
In Py3k the ob_sstate has gone away (from PyBytesObject), so another
approach would be needed (e.g. add an indirection to PyBytesObject).
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com