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
Peephole binops folding can lead to memory and bytecache ballooning #74479
Comments
The following expression produces 127MB in constants in
The optimizer already does not store optimized *sequences* of more than 20 elements to avoid making bytecode files too large: If the new constant is a sequence, only folds when the size Perhaps the same should be extended to number objects? |
A few thoughts:
|
Looking back at the OP's timings in the referenced SO question, I would expect that if someone "fixed" this issue, it wouldn't be long before someone else filed a performance regression bug claiming a 63,000x slowdown in exactly the same code. I'm marking this as closed because if this ever did arise in real code, it is unclear whether the desirable behavior is to eat memory but run fast, or to save memory upfront but run dog slow and eat memory later when the function is called. Either way, the situation is likely to be very rare. Your guess is as good as mine regarding which behavior would be more desirable to the user. Presumably, if they direct the computer to build a large object, they won't be surprised if a large object is created. |
Thanks Raymond, for the response. I agree, we can't prevent all possible misuse, and avoiding the memory issue would require overly costly checks as to what is being multiplied or added. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: