Comments on optimizations around string concatenation.
Note: The code links are to CPython 3.8.5, the most recent release when this was written.
I was recently asked about a performance optimization in CPython around using
+ for string objects.
As some people may already know, if you use
+ a string, it can sometimes be just as fast as
The question was to explain when that optimization couldn't be performed.
We will be going through the following example scenarios: