Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
GH-93516: Speedup line number checks when tracing.#93763
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
6b2d84047cb2edc0873083e5d1fdFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -62,7 +62,8 @@ typedef uint16_t _Py_CODEUNIT; | ||
| PyObject *co_exceptiontable; /* Byte string encoding exception handling \ | ||
| table */ \ | ||
| int co_flags; /* CO_..., see below */ \ | ||
| short co_warmup; /* Warmup counter for quickening */ \ | ||
| short _co_linearray_entry_size; /* Size of each entry in _co_linearray */ \ | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Not a big deal since you were able to squeeze this in here, but we might want to consider making this the first byte of the line array (or a flag on the code object) if we end up getting rid of MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I originally made it a bit in | ||
| \ | ||
| /* The rest are not so impactful on performance. */ \ | ||
| int co_argcount; /* #arguments, except *args */ \ | ||
| @@ -90,6 +91,7 @@ typedef uint16_t _Py_CODEUNIT; | ||
| PyObject *co_weakreflist; /* to support weakrefs to code objects */ \ | ||
| void *_co_code; /* cached co_code object/attribute */ \ | ||
| int _co_firsttraceable; /* index of first traceable instruction */ \ | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I missed when this was added, but maybe we could move this member up with the other MemberAuthor
| ||
| char *_co_linearray; /* array of line offsets */ \ | ||
| /* Scratch space for extra data relating to the code object. \ | ||
| Type is a void* to keep the format private in codeobject.c to force \ | ||
| people to go through the proper APIs. */ \ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -463,6 +463,35 @@ adaptive_counter_backoff(uint16_t counter) { | ||
| } | ||
| /* Line array cache for tracing */ | ||
| extern int _PyCode_CreateLineArray(PyCodeObject *co); | ||
| static inline int | ||
| _PyCode_InitLineArray(PyCodeObject *co) | ||
| { | ||
| if (co->_co_linearray) { | ||
| return 0; | ||
| } | ||
| return _PyCode_CreateLineArray(co); | ||
| } | ||
| static inline int | ||
| _PyCode_LineNumberFromArray(PyCodeObject *co, int index) | ||
| { | ||
| assert(co->_co_linearray != NULL); | ||
| assert(index >= 0); | ||
markshannon marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| assert(index < Py_SIZE(co)); | ||
| if (co->_co_linearray_entry_size == 2) { | ||
| return ((int16_t *)co->_co_linearray)[index]; | ||
| } | ||
| else { | ||
| assert(co->_co_linearray_entry_size == 4); | ||
| return ((int32_t *)co->_co_linearray)[index]; | ||
| } | ||
| } | ||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Lazily create a table mapping bytecode offsets to line numbers to speed up | ||
| calculation of line numbers when tracing. |