-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
bpo-43846: Use less stack for large literals and calls #25403
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
bpo-43846: Use less stack for large literals and calls #25403
Conversation
gvanrossum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG, just a few extreme nits.
Python/compile.c
Outdated
| if (n+pushed >= STACK_USE_GUIDELINE) { | ||
| ADDOP_I(c, build, pushed); | ||
| seen_star = 1; | ||
| } | ||
| else { | ||
| seen_star = 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I suppose you could just set seen_star = 0 here and emit the push in the for-loop below when i+n exceeds the limit (and it hasn't been emitted yet). FWIW I wish during this phase the variable was called something like 'build_emitted', since that is really what it's keeping track of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I used sequence_built and also cleaned up the surrounding code a bit.
| ADDOP_I(c, BUILD_STRING, asdl_seq_LEN(e->v.JoinedStr.values)); | ||
|
|
||
| Py_ssize_t value_count = asdl_seq_LEN(e->v.JoinedStr.values); | ||
| if (value_count > STACK_USE_GUIDELINE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use >= for consistency with earlier locations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used > throughout. It seems to fit better with STACK_USE_GUIDELINE being the maximum stack use.
Python/compile.c
Outdated
| PyObject *keys, *key; | ||
| assert(n > 0); | ||
| if (n > 1) { | ||
| int big = n > STACK_USE_GUIDELINE/2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto?
…DELINE use the same comparison.
Prevents excessive stack usage for oversized calls and literals.
Having a soft upper limit on stack usage allows us to design more efficient stack layouts
without worrying about code that uses huge amounts of stack.
As giant literals and calls are rare, this PR should have negligible effect on performance.
https://bugs.python.org/issue43846