Merge co_names and co_consts into a single array. #128
Replies: 13 comments
-
Are there no backwards compatibility issues? They are both part of the api. Also, would this make the consts not immutable from user code? That would probably be an api change. |
Beta Was this translation helpful? Give feedback.
-
That would be easy to validate by counting these numbers in the top 100 or 5000 packages on GitHub. |
Beta Was this translation helpful? Give feedback.
-
Using the top 1000 PyPI packages, I got 0.14% of code objects having more than 256 total names and constants combined.
https://github.com/pxeger/pycstats Edit: updated data with top 1000 packages |
Beta Was this translation helpful? Give feedback.
-
But how often are they >= 255 together? Also, it looks like to minimize extended-arg opcodes we need to place the names first. (The dynamic profile could theoretically be different, but that feels unlikely.) |
Beta Was this translation helpful? Give feedback.
-
I'm not sure what you mean by "But how often are they >= 255 together?". The 0.12% number is already the proportion for which |
Beta Was this translation helpful? Give feedback.
-
Oh, d’oh. Of course. Sorry! |
Beta Was this translation helpful? Give feedback.
-
The array would be internal, so could not be mutated. |
Beta Was this translation helpful? Give feedback.
-
Could you update the initial comment to clarify that (a lot)? This wasn't obvious to me at all (though I'm sure it was in your mind when you wrote it down :-). |
Beta Was this translation helpful? Give feedback.
-
I didn't want to shackle whoever was going to implement it :) Now that I've given a bit of thought, here's another way to implement it: The consts and names go in the same array (names first, but it doesn't really matter), and we store a pointer to the first const. E.g. names:
|
Beta Was this translation helpful? Give feedback.
-
When I experimented with MAKE_INT there was a noticeable difference in micro benchmarks between the opcode doing small_ints[oparg] and small_ints[oparg-5]. |
Beta Was this translation helpful? Give feedback.
-
@iritkatriel OOI what was the difference between the two? |
Beta Was this translation helpful? Give feedback.
-
Start here: #65 (comment) |
Beta Was this translation helpful? Give feedback.
-
Presumably |
Beta Was this translation helpful? Give feedback.
-
Merging
co_names
andco_consts
would have some significant benefits:The obvious downside is for functions where the total number of names and constants exceeds 256. I hypothesize that those functions are rare, but don't have data to confirm that.
This is probably best left until https://bugs.python.org/issue36521 has been resolved.
Beta Was this translation helpful? Give feedback.
All reactions