bpo-43846: Use less stack for large literals and calls#25403
Merged
markshannon merged 6 commits intopython:masterfrom Apr 15, 2021
Merged
bpo-43846: Use less stack for large literals and calls#25403markshannon merged 6 commits intopython:masterfrom
markshannon merged 6 commits intopython:masterfrom
Conversation
gvanrossum
approved these changes
Apr 14, 2021
Member
gvanrossum
left a comment
There was a problem hiding this comment.
LG, just a few extreme nits.
Python/compile.c
Outdated
Comment on lines
+3797
to
+3803
| if (n+pushed >= STACK_USE_GUIDELINE) { | ||
| ADDOP_I(c, build, pushed); | ||
| seen_star = 1; | ||
| } | ||
| else { | ||
| seen_star = 0; | ||
| } |
Member
There was a problem hiding this comment.
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.
Member
Author
There was a problem hiding this comment.
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) { |
Member
There was a problem hiding this comment.
Maybe use >= for consistency with earlier locations?
Member
Author
There was a problem hiding this comment.
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; |
…DELINE use the same comparison.
This was referenced Jun 27, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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