[Python-ideas] Briefer string format

Steve Dower Steve.Dower at microsoft.com
Tue Jul 21 05:16:05 CEST 2015

Sounds like you deserve the congratulations then :)

But when you've confirmed that string formatting is something that can be changed to improve performance (specifically parsing the format string in this case), you have options regardless of the default optimization. For instance, you probably want to preallocate a list, format and set each non-string item, then use .join (or if possible, write directly from the list without the intermediate step of producing a single string).

Making f"" strings subtly faster isn't going to solve your performance issue, and while I'm not advocating wastefulness, this looks like a premature optimization, especially when put alongside the guaranteed heap allocations and very likely IO that are also going to occur.


Top-posted from my Windows Phone
From: Alexander Belopolsky<mailto:alexander.belopolsky at gmail.com>
Sent: ‎7/‎20/‎2015 19:44
To: Steve Dower<mailto:Steve.Dower at microsoft.com>
Cc: Eric V. Smith<mailto:eric at trueblade.com>; python-ideas<mailto:python-ideas at python.org>
Subject: Re: [Python-ideas] Briefer string format

On Mon, Jul 20, 2015 at 10:10 PM, Steve Dower <Steve.Dower at microsoft.com<mailto:Steve.Dower at microsoft.com>> wrote:
If text formatting is your bottleneck, congratulations on fixing your network, disk, RAM and probably your users.

Thank you, but one of my servers just spent 18 hours loading 10GB of XML data into a database.  Given that CPU was loaded 100% all this time, I suspect neither network nor disk and not even RAM was the bottleneck.  Since XML parsing was done by C code and only formatting of database INSERT instructions was done in Python, I strongly suspect string formatting had a sizable carbon footprint in this case.

Not all string formatting is done for human consumption.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150721/48dbb5f2/attachment-0001.html>

More information about the Python-ideas mailing list