[Python-Dev] The "lazy strings" patch [was: PATCH submitted: Speed up + for string concatenation, now as fast as "".join(x) idiom]
Larry Hastings
larry at hastings.org
Sat Nov 4 07:38:45 CET 2006
On 2006/10/20, Larry Hastings wrote:
> I'm ready to post the patch.
Sheesh! Where does the time go.
I've finally found the time to re-validate and post the patch. It's
SF.net patch #1590352:
http://sourceforge.net/tracker/index.php?func=detail&aid=1590352&group_id=5470&atid=305470
I've attached both the patch itself (against the current 2.6 revision,
52618) and a lengthy treatise on the patch and its ramifications as I
understand them.
I've also added one more experimental change: a new string method,
str.simplify(). All it does is force a lazy concatenation / lazy slice
to render. (If the string isn't a lazy string, or it's already been
rendered, str.simplify() is a no-op.) The idea is, if you know these
consarned "lazy slices" are giving you the oft-cited horrible memory
usage scenario, you can tune your app by forcing the slices to render
and drop their references. 99% of the time you don't care, and you
enjoy the minor speedup. The other 1% of the time, you call .simplify()
and your code behaves as it did under 2.5. Is this the right approach?
I dunno. So far I like it better than the alternatives. But I'm open
to suggestions, on this or any other aspect of the patch.
Cheers,
/larry/
More information about the Python-Dev
mailing list