Repository navigation
BUG: chr() leaks #4422
Description
Activity
"".join([chr(x//3) for x in (261, 312, 291, 348, 117, 345, 96, 348, 312, 315, 345, 189)])Title is explicit enough no ?
run code, enjoy MemoryError after a while on any port, unix port is good enough for that or pycopy with a esp sized heap.edit / finally on a side note i spent 4 hours finding that and sent issue in a hurry before work, so you could give a 30 seconds to at least test the snippet instead of writing your own. if i'm wrong i will deeply apologize for wasting your precious time.
Look how much info can be packed into human words ;-).
or pycopy with a esp sized heap.
Good mentioning, because aggressive string interning introduced by @dpgeorge was one of the few patches I reverted (so far) in my fork.
But otherwise, yeah, looking at mp_builtin_chr(), it interns unconditionally. A solution would be interning only ASCII stuff by default, allow to disable interning in optional cases (like this) altogether.
"unconditionally" => that may explain why my doubts probably left me speechless at first.
- short strings should not be interned at all.
- at worst, interning should be kept on MRU cache decisions not unconditionally.
- at best interning really long strings should be paged to flash ( like arduino progmem ? ) on user request, maybe via a custom type or simply just with f"" ( like cpython f-strings syntax ) ?.
short strings should not be interned at all.
Obviously the opposite. And quite obviously actually:
- Shorter strings have a higher chance of reuse (and that's why they're interned at all).
- Allocating short strings has highest overhead. E.g. for 1 useful char, a whole 16-byte alloc block is used, 93% wasted. Surely, not allocating them like that is better.
by short i meant len() < sizeof( hash + storage pointer )
See #2280.
thx for incrementing the reference counter ;)
a tested working fix is available here https://github.com/pfalcon/pycopy/commit/4d7a02654d37024d73f83d47f992f2dd91e2d8b7.diff
- added a commit that references this issue
on Apr 8, 2021 No MemoryError when running this on Unix port with version v1.24.0-preview.276.g1897fe6227. But it seems to stop at
154 0 11296 156 0 11296which seems way to early?
- addedpy-coreRelates to py/ directory in sourceRelates to py/ directory in source
on Sep 29, 2024