Quantcast

[issue14687] Optimize str%tuple for the PEP 393

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[issue14687] Optimize str%tuple for the PEP 393

STINNER Victor

New submission from STINNER Victor <[hidden email]>:

PyUnicode_Format() creates short temporary substrings. Attached patch tries to avoid substrings. For example, it avoids write of 1 character and repetition of 1 character like a space. PyUnicode_Format() now works in two steps:

 - computes the maximum character and the length of the output string
 - write characters into the output string

I'm not sure that my patch is correct, nor that the change does really speed-up Python.


Benchmark:

./python -m timeit \
  -s 's="x=%s, y=%u, z=%x"; args=(123, 456, 789)' \
  's%args'
./python -m timeit \
  -s 's="The %(k1)s is %(k2)s the %(k3)s."; args={"k1":"x","k2":"y","k3":"z",}' \
  's%args'

Python 3.2:

1000000 loops, best of 3: 0.482 usec per loop
1000000 loops, best of 3: 0.295 usec per loop

Python 3.3:

1000000 loops, best of 3: 0.653 usec per loop
1000000 loops, best of 3: 0.666 usec per loop

Python 3.3 + patch:

1000000 loops, best of 3: 0.596 usec per loop
1000000 loops, best of 3: 0.566 usec per loop

----------
files: pyunicode_format.patch
keywords: patch
messages: 159508
nosy: haypo, loewis, pitrou
priority: normal
severity: normal
status: open
title: Optimize str%tuple for the PEP 393
type: performance
versions: Python 3.3
Added file: http://bugs.python.org/file25388/pyunicode_format.patch

_______________________________________
Python tracker <[hidden email]>
<http://bugs.python.org/issue14687>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/lists%2B1322467933539-512619%40n6.nabble.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[issue14687] Optimize str%tuple for the PEP 393

STINNER Victor

Serhiy Storchaka <[hidden email]> added the comment:

I see sped up +10% on Intel Atom (but 3.2 still 2x fast).

With non-ascii arguments speed up can be a little bit larger.

----------
nosy: +storchaka

_______________________________________
Python tracker <[hidden email]>
<http://bugs.python.org/issue14687>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/lists%2B1322467933539-512619%40n6.nabble.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[issue14687] Optimize str%tuple for the PEP 393

STINNER Victor
In reply to this post by STINNER Victor

STINNER Victor <[hidden email]> added the comment:

Updated patch:
 - use also PyUnicode_Kind for kind and fmtkind
 - fix compiler warnings
 - initialize data outside the loop
 - avoid duplicate PyUnicode_READ() where it is possible
 - minor code cleanup

----------
Added file: http://bugs.python.org/file25413/pyunicode_format-2.patch

_______________________________________
Python tracker <[hidden email]>
<http://bugs.python.org/issue14687>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/lists%2B1322467933539-512619%40n6.nabble.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[issue14687] Optimize str%tuple for the PEP 393

STINNER Victor
In reply to this post by STINNER Victor

Roundup Robot <[hidden email]> added the comment:

New changeset 42fbb4f9b540 by Victor Stinner in branch 'default':
Issue #14687: Cleanup PyUnicode_Format()
http://hg.python.org/cpython/rev/42fbb4f9b540

New changeset 08b54c635586 by Victor Stinner in branch 'default':
Issue #14687: Avoid an useless duplicated string in PyUnicode_Format()
http://hg.python.org/cpython/rev/08b54c635586

----------
nosy: +python-dev

_______________________________________
Python tracker <[hidden email]>
<http://bugs.python.org/issue14687>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/lists%2B1322467933539-512619%40n6.nabble.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[issue14687] Optimize str%tuple for the PEP 393

STINNER Victor
In reply to this post by STINNER Victor

Roundup Robot <[hidden email]> added the comment:

New changeset 4b98ce6ef95e by Victor Stinner in branch 'default':
Issue #14687: Optimize str%args
http://hg.python.org/cpython/rev/4b98ce6ef95e

New changeset a966f9311ebb by Victor Stinner in branch 'default':
Issue #14687: Cleanup PyUnicode_Format()
http://hg.python.org/cpython/rev/a966f9311ebb

----------

_______________________________________
Python tracker <[hidden email]>
<http://bugs.python.org/issue14687>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/lists%2B1322467933539-512619%40n6.nabble.com

Loading...