[issue46990] Surprising list overallocation from .split()

2022-03-11 Thread Tim Peters
Tim Peters added the comment: Well, that's annoying ;-) In context, the OP was saving a list of 10 million splits. So each overallocation by a single element burned 80 million bytes of RAM. Overallocating by 7 burned 560 million bytes. Which is unusual. Usually a split result is short-lived,

[issue46990] Surprising list overallocation from .split()

2022-03-11 Thread Jelle Zijlstra
Jelle Zijlstra added the comment: The value 12 is hardcoded here: https://github.com/python/cpython/blob/a89c29fbcc7e7e85848499443d819c3fab68c78a/Objects/stringlib/split.h#L14 The comment there says that this is because most .split() calls are on lines of human-readable text, which has about

[issue46990] Surprising list overallocation from .split()

2022-03-11 Thread Tim Peters
Change by Tim Peters : -- type: behavior -> resource usage ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: ht

[issue46990] Surprising list overallocation from .split()

2022-03-11 Thread Tim Peters
New submission from Tim Peters : When looking into a StackOverflow question about surprisingly high memory use, I stumbled into this (under 3.10.1, Win64): >>> import sys >>> s = "1 2 3 4 5".split() >>> s ['1', '2', '3', '4', '5'] >>> sys.getsizeof(s) 152 >>> _ - sys.getsizeof([]) 96 >>> 96 /