New GitHub issue #100817 from sobolevn:<br>

<hr>

<pre>
## `slice`

Right now `slice` objects are deepcopied using `__reduce__` defined as:
https://github.com/python/cpython/blob/26ff43625ed7bf09542ad8f149cb6af710b41e15/Objects/sliceobject.c#L559-L563

It is one of last branches of `deepcopy` logic:
https://github.com/python/cpython/blob/26ff43625ed7bf09542ad8f149cb6af710b41e15/Lib/copy.py#L120-L157

But, since `slice` is an immutable type, we can optimize its `deepcopy` as:

```python
d[slice] = _deepcopy_atomic
```

Before:

```
» pyperf timeit --setup 'from copy import deepcopy; s = slice(1,10,2)' 'deepcopy(s)'
.....................
Mean +- std dev: 3.46 us +- 0.18 us
```

After:

```
» pyperf timeit --setup 'from copy import deepcopy; s = slice(1,10,2)' 'deepcopy(s)'
.....................
Mean +- std dev: 277 ns +- 3 ns
```

Looks like a good speedup for just a single line!
Noticed while working on #100815 

PR is incoming.
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/100817">View on GitHub</a>
<p>Labels: type-feature, performance</p>
<p>Assignee: sobolevn</p>