This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author BTaskaya
Recipients BTaskaya, eric.smith, pablogsal, serhiy.storchaka
Date 2021-05-20.19:03:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1621537414.24.0.919441492854.issue44194@roundup.psfhosted.org>
In-reply-to
Content
Since strings are immutable types, we could fold some operation on top of them. Serhiy has done some work on issue 28307 regarding folding `str % args` combination, which I think we can extend even further. One simple example that I daily encounter is that, there is this pattern

'/'.join([something, something_else, user_arg])

where people would join N number of elements together with a separator, where the N is something that we know. Just a search over some locally cloned PyPI projects (a couple thousand, showed 5000+ occurrences where this optimization applies).

The preliminary benchmarks indicate that the speedup is about %40. Though there are multiple issues that might concern others:
   - type checking, f-strings cast automatically but .join() requires each element to be a string subclass. The current implementation introduces a new conversion called 'c' which actually does the type checking instead of converting the value.
   - preventing a call to a runtime function, I belive that this work is not that different than issue 28307 which prevents str.__mod__ though I understand the concern

Here is the implementation if anybody wants to take a look at it: https://github.com/isidentical/cpython/commit/d7ea8f6e38578ba06d28deb4b4a8df676887ec26

I believe that the implementation can be optimized further (etc if a continuous block of elements are a string, then we can load all of them in one go!). And some cases proved that the f-strings might be faster than the join by 1.7-1.8x.
History
Date User Action Args
2021-05-20 19:03:34BTaskayasetrecipients: + BTaskaya, eric.smith, serhiy.storchaka, pablogsal
2021-05-20 19:03:34BTaskayasetmessageid: <1621537414.24.0.919441492854.issue44194@roundup.psfhosted.org>
2021-05-20 19:03:34BTaskayalinkissue44194 messages
2021-05-20 19:03:33BTaskayacreate