PERF: Add if branch for empty sep in str.cat
State: closed

Follow-up to #23167, resp dropping py2. The branch I'm readding here had to be deleted originally to pass some python2 bytes-tests. In case there is no separator, we can avoid all the list-ops and speed up cat_core by a fair bit.

Labels:
name: Performance
description: Memory or execution speed performance
name: Strings
description: String extension data type and string data

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26605?src=pr&el=h1) Report
> Merging [#26605](https://codecov.io/gh/pandas-dev/pandas/pull/26605?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/0fd888c8b318d4041b0ae53c64715eca0d345dd3?src=pr&el=desc) will **decrease** coverage by `1.17%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/26605/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26605?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26605      +/-   ##
==========================================
- Coverage   93.02%   91.84%   -1.18%     
==========================================
  Files         182      174       -8     
  Lines       50253    50709     +456     
==========================================
- Hits        46746    46576     -170     
- Misses       3507     4133     +626
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.39% <100%> (-1.3%)` | :arrow_down: |
| #single | `41.76% <0%> (-0.75%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26605?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/strings.py](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvc3RyaW5ncy5weQ==) | `98.92% <100%> (-0.02%)` | :arrow_down: |
| [pandas/plotting/\_misc.py](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19taXNjLnB5) | `38.23% <0%> (-26.63%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-21.06%)` | :arrow_down: |
| [pandas/io/gcs.py](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2djcy5weQ==) | `80% <0%> (-20%)` | :arrow_down: |
| [pandas/io/s3.py](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3MzLnB5) | `89.47% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/groupby/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9iYXNlLnB5) | `91.83% <0%> (-8.17%)` | :arrow_down: |
| [pandas/io/excel/\_xlrd.py](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2V4Y2VsL194bHJkLnB5) | `94.54% <0%> (-5.46%)` | :arrow_down: |
| [pandas/util/\_decorators.py](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvX2RlY29yYXRvcnMucHk=) | `91.34% <0%> (-4.01%)` | :arrow_down: |
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `83.77% <0%> (-3.88%)` | :arrow_down: |
| [pandas/io/formats/printing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvcHJpbnRpbmcucHk=) | `85.56% <0%> (-3.28%)` | :arrow_down: |
| ... and [171 more](https://codecov.io/gh/pandas-dev/pandas/pull/26605/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26605?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26605?src=pr&el=footer). Last update [0fd888c...2e0d03a](https://codecov.io/gh/pandas-dev/pandas/pull/26605?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Finally got around to running the ASVs:
```
>asv continuous -f 1.1 upstream/master HEAD -b ^strings.Cat
[...]
       before           after         ratio
     [0fd888c8]       [2e0d03a9]
     <master>         <str_cat_perf>
-      59.9±0.6ms       53.0±0.4ms     0.88  strings.Cat.time_cat(3, None, '-', 0.0)
-      60.0±0.2ms       52.7±0.1ms     0.88  strings.Cat.time_cat(3, None, None, 0.0)

SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.
```

Note that this is for N=10000:
https://github.com/pandas-dev/pandas/blob/0fd888c8b318d4041b0ae53c64715eca0d345dd3/asv_bench/benchmarks/strings.py#L116

I believe the gains would be even better for larger arrays.
k thanks