You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To prepare gh-119182 implementation, I propose to optimize first the _PyUnicodeWriter implementation. For example, optimize the UTF-8 decoder in PyUnicode_FromFormat() by avoiding the creation of a temporary buffer: write directly characters in the writer.
I do not know how much this is needed, but the code looks correct.
Could you please collect some data about types used with %S and %R? And how often %S and %R are used with and without the width and the precision? Just add writing the type name in the special log file and run the test suite, then count most common names.
Thank you. According to these results we can ignore int and float and only optimize str. Of course, the data obtained in such way is very rough estimation of real world usage, but the difference is too large.
Unfortunately, %R for str is not optimized in this PR, and the usage of str with %S is not overwhelming, so this optimization can have very minor effect. I am not sure now that the gain is worth the cost.
Activity
pythongh-119396: Optimize %S format of PyUnicode_FromFormat()
serhiy-storchaka commentedon May 22, 2024
I do not know how much this is needed, but the code looks correct.
Could you please collect some data about types used with
%Sand%R? And how often%Sand%Rare used with and without the width and the precision? Just add writing the type name in the special log file and run the test suite, then count most common names.vstinner commentedon May 22, 2024
Sure, here you have (I didn't check width or precision):
Details
For str, int and float:
Patch:
serhiy-storchaka commentedon May 22, 2024
Thank you. According to these results we can ignore
intandfloatand only optimizestr. Of course, the data obtained in such way is very rough estimation of real world usage, but the difference is too large.Unfortunately,
%Rforstris not optimized in this PR, and the usage ofstrwith%Sis not overwhelming, so this optimization can have very minor effect. I am not sure now that the gain is worth the cost.vstinner commentedon May 22, 2024
I also write PR gh-119398 for this issue: "Optimize PyUnicode_FromFormat() UTF-8 decoder".
gh-119396: Optimize PyUnicode_FromFormat() UTF-8 decoder (#119398)
pythongh-119396: Optimize unicode_repr()
gh-119396: Optimize unicode_repr() (#119617)
gh-119396: Optimize unicode_decode_utf8_writer() (#119957)
pythongh-119396: Optimize unicode_decode_utf8_writer() (python#119957)
pythongh-119396: Optimize unicode_decode_utf8_writer() (python#119957)
pythongh-119396: Optimize unicode_decode_utf8_writer() (python#119957)
pythongh-119396: Optimize PyUnicode_FromFormat() UTF-8 decoder (pytho…
pythongh-119396: Optimize unicode_repr() (python#119617)
pythongh-119396: Optimize unicode_decode_utf8_writer() (python#119957)