-
Notifications
You must be signed in to change notification settings - Fork 49
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
Add instructions for creating small objects. #609
Comments
I am definitely in favor of Let's look at For short strings and medium-sized integers, we can store up to 4 bytes of data using |
Considering that there is already a table of frequent strings (I recall it containing the empty string and the one character strings of printable characters), there could be LOAD_FIXED_STR that gets an index into this table. |
We've added |
When we use a small constant in Python code, we compile it as
LOAD_CONST
.This looks efficient, but ignores the fact that the constant object has to be created by marshal, which is quite slow compared to the main interpreter.
This is fine for code in functions as they are expected to be executed many times, but for run once code, like module and class code, this is not so good.
Rather than have marshal create the object, to be put in a constants array to be used only once, we should create the objects in bytecode.
To do that, we want to add the following instructions:
LOAD_INT
: Loads a small int (0-255)MAKE_FLOAT
: Makes a float.MAKE_ASCII
: Makes a string from ASCII dataMAKE_UNICODE
: Makes a string from UTF-8 dataMAKE_LONG
: Make a long object from an array of bytes.These bytecodes are needed for #566, so this would be a useful halfway-house.
Where to put the data?
In #566 I suggest a separate array.
That won't work here because there is no separate array, but there is no reason why it cannot follow the instruction.
It would make disassembly harder, but shouldn't matter for performance, as we don't expect to be branching much in the run-once code.
For this to be efficient, we need to avoid copying and traversing the code of the code object too many times.
See
#608#462#566 [Guido: I think that it's now #566, since #462 is closed] for how to deal with this.This complements #583 which reduces code object size, and thus code object loading time.
The text was updated successfully, but these errors were encountered: