[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-18 Thread Xiang Zhang
Xiang Zhang added the comment: > My question is simple: in what circumstances the patch has an effect? My original intention is that there is no need for the caller to check for the empty string. Even there is no use case now, it could be in future. But Serhiy, I am actually very glad to get

[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: My question is simple: in what circumstances the patch has an effect? -- ___ Python tracker ___

[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-18 Thread STINNER Victor
STINNER Victor added the comment: > We should know what is the benefit of the patch before committing it. The purpose of the patch is to use the empty string singleton to reduce the memory footprint, instead of creating multiple empty (Unicode) string objects. --

[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-18 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I know that _PyUnicode_FromASCII() is called with size=0. But most callers call it only with size!=0. I didn't investigate further. We should know what is the benefit of the patch before committing it. Just "for consistency" is a weak argument itself.

[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-18 Thread STINNER Victor
STINNER Victor added the comment: To reduce the memory footprint, it's important that we reuse internal Unicode singletons. For the empty string singleton, you have two choices: * if length is equal to zero, return the singleton * create a string and then call unicode_result()

[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-06 Thread Xiang Zhang
Xiang Zhang added the comment: IMHO, _PyUnicode_FromASCII is a private API and could be used in other places in future. We should not rely on the caller to check and return the singleton empty string. -- ___ Python tracker

[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-11-06 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The case for size=0 often is handled before calling _PyUnicode_FromASCII. In what circumstances _PyUnicode_FromASCII is called with size=0? Is this case covered by tests? -- ___ Python tracker

[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-10-09 Thread Xiang Zhang
Xiang Zhang added the comment: The cost is really small (an integer compare vs memory malloc and copy). The advantages are fast path for empty strings and retaining consistency with other codes in unicodeobject.c. You can see other places use the same optimization, e.g. PyUnicode_FromUnicode,

[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-10-09 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Additional check has a non-zero cost. What is the benefit of this change? -- ___ Python tracker ___

[issue28398] Return singleton empty string in _PyUnicode_FromASCII

2016-10-09 Thread Xiang Zhang
New submission from Xiang Zhang: Right now in _PyUnicode_FromASCII, it only optimises for size 1 not size 0. All other places getting the same situation in unicodeobject.c do both. -- files: _PyUnicode_FromASCII.patch keywords: patch messages: 278364 nosy: haypo, serhiy.storchaka,