bpo-43846: Use less stack for large literals and calls#25403
bpo-43846: Use less stack for large literals and calls#25403markshannon merged 6 commits intopython:masterfrom
Conversation
gvanrossum
left a comment
There was a problem hiding this comment.
LG, just a few extreme nits.
| 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.
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.
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.
Maybe use >= for consistency with earlier locations?
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.
| PyObject *keys, *key; | ||
| assert(n > 0); | ||
| if (n > 1) { | ||
| int big = n > STACK_USE_GUIDELINE/2; |
…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