CoW: Use exponential backoff when clearing dead references
State: closed

- [x] closes #55245 (Replace xxxx with the GitHub issue number)
- [x] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [x] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [x] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.


I'd rather keep @rhshadrach 's issue open, we might be able to find a better fix there

The runtime is back to what he had initially on this branch, e.g. 3ms on Joris examples and 1s on Richards issue

Labels:
name: Performance
description: Memory or execution speed performance
name: Regression
description: Functionality that used to work in a prior pandas version
name: Copy / view semantics

Comments:
Can you add a test that just adds blocks to a ``BlockValuesRef`` to make sure the exponential backoff is working as expected?
Tests are a good idea, added the relevant cases
Edit: Lots of false positives on the first run, reran individual ASVs. No perf regressions.

<details>
<summary>ASVs for d4c159b5</summary>

```
| Change   | Before [0021d241] <cow_dead_regf~4>   | After [d4c159b5] <cow_dead_regf>   |   Ratio | Benchmark (Parameter)                                                                                                                                              |
|----------|---------------------------------------|------------------------------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| -        | 541±20ns                              | 491±20ns                           |    0.91 | index_cached_properties.IndexCache.time_values('UInt64Index')                                                                                                      |
| -        | 612±20ns                              | 551±30ns                           |    0.9  | index_cached_properties.IndexCache.time_inferred_type('DatetimeIndex')                                                                                             |
| -        | 237±20ns                              | 214±3ns                            |    0.9  | indexing_engines.NumericEngineIndexing.time_get_loc_near_middle((<class 'pandas._libs.index.Int64Engine'>, <class 'numpy.int64'>), 'non_monotonic', True, 100000)  |
| -        | 59.3±1ms                              | 53.1±1ms                           |    0.9  | io.json.ToJSONWide.time_to_json('values', 'df_int_float_str')                                                                                                      |
| -        | 1.34±0.1ms                            | 1.21±0.01ms                        |    0.9  | io.parsers.ConcatDateCols.time_check_concat(1234567890, 2)                                                                                                         |
| -        | 26.6±0.7ms                            | 23.9±0.8ms                         |    0.9  | io.stata.Stata.time_read_stata('ty')                                                                                                                               |
| -        | 47.1±2ms                              | 42.6±0.3ms                         |    0.9  | strings.Methods.time_findall('string[python]')                                                                                                                     |
| -        | 9.52±1μs                              | 8.60±0.06μs                        |    0.9  | timeseries.TzLocalize.time_infer_dst(tzutc())                                                                                                                      |
| -        | 859±20ns                              | 777±30ns                           |    0.9  | tslibs.tslib.TimeIntsToPydatetime.time_ints_to_pydatetime('timestamp', 0, tzlocal())                                                                               |
| -        | 252±2μs                               | 224±20μs                           |    0.89 | algos.isin.IsIn.time_isin_categorical('string[python]')                                                                                                            |
| -        | 2.27±0.03ms                           | 2.03±0.02ms                        |    0.89 | frame_methods.Apply.time_apply_pass_thru                                                                                                                           |
| -        | 23.9±2μs                              | 21.4±0.4μs                         |    0.89 | groupby.GroupByMethods.time_dtype_as_group('uint', 'count', 'direct', 1, 'cython')                                                                                 |
| -        | 242±20ns                              | 215±4ns                            |    0.89 | indexing_engines.NumericEngineIndexing.time_get_loc_near_middle((<class 'pandas._libs.index.Int64Engine'>, <class 'numpy.int64'>), 'monotonic_decr', True, 100000) |
| -        | 128±2μs                               | 111±2μs                            |    0.87 | algos.isin.IsIn.time_isin_categorical('uint64')                                                                                                                    |
| -        | 111±2ms                               | 96.2±2ms                           |    0.87 | groupby.Transform.time_transform_lambda_max                                                                                                                        |
| -        | 321±20ns                              | 280±20ns                           |    0.87 | index_cached_properties.IndexCache.time_inferred_type('Int64Index')                                                                                                |
| -        | 671±80ns                              | 587±30ns                           |    0.87 | index_cached_properties.IndexCache.time_is_monotonic_decreasing('Int64Index')                                                                                      |
| -        | 613±60μs                              | 526±4μs                            |    0.86 | arithmetic.IntFrameWithScalar.time_frame_op_with_scalar(<class 'numpy.int64'>, 4, <built-in function mul>)                                                         |
| -        | 13.2±0.1ms                            | 11.4±0.07ms                        |    0.86 | indexing.DataFrameNumericIndexing.time_loc_dups(<class 'numpy.float64'>, 'unique_monotonic_inc')                                                                   |
| -        | 21.0±0.4ms                            | 17.9±0.6ms                         |    0.85 | frame_methods.Fillna.time_bfill(True, 'object')                                                                                                                    |
| -        | 13.7±0.1ms                            | 11.5±0.09ms                        |    0.84 | indexing.DataFrameNumericIndexing.time_loc_dups(<class 'numpy.float64'>, 'nonunique_monotonic_inc')                                                                |
| -        | 1.98±0.01ms                           | 1.64±0.03ms                        |    0.83 | join_merge.Concat.time_concat_series(0)                                                                                                                            |
| -        | 24.1±0.2ms                            | 19.8±0.1ms                         |    0.82 | tslibs.normalize.Normalize.time_is_date_array_normalized(1000000, <DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>)                                                |
| -        | 44.9±0.3ms                            | 36.1±0.4ms                         |    0.8  | frame_methods.Duplicated.time_frame_duplicated_wide                                                                                                                |
| -        | 3.17±0.04μs                           | 2.54±0.01μs                        |    0.8  | tslibs.normalize.Normalize.time_is_date_array_normalized(100, <DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>)                                                    |
| -        | 250±0.4μs                             | 201±3μs                            |    0.8  | tslibs.normalize.Normalize.time_is_date_array_normalized(10000, <DstTzInfo 'US/Pacific' LMT-1 day, 16:07:00 STD>)                                                  |
| -        | 6.24±2ms                              | 4.67±0.02ms                        |    0.75 | sparse.GetItemMask.time_mask(nan)                                                                                                                                  |
| -        | 6.39±0.03ms                           | 4.75±0.03ms                        |    0.74 | frame_methods.AsType.time_astype(('float64', 'Float64'), False)                                                                                                    |
| -        | 6.72±0.1ms                            | 4.94±0.01ms                        |    0.74 | frame_methods.AsType.time_astype(('float64', 'float64[pyarrow]'), False)                                                                                           |
| -        | 10.0±0.3μs                            | 7.48±0.08μs                        |    0.74 | timeseries.TzLocalize.time_infer_dst(None)                                                                                                                         |
| -        | 24.9±1ms                              | 18.1±0.5ms                         |    0.73 | reindex.Reindex.time_reindex_multiindex_with_cache                                                                                                                 |
| -        | 2.43±0.01ms                           | 1.72±0.02ms                        |    0.71 | reshape.ReshapeExtensionDtype.time_stack('datetime64[ns, US/Pacific]')                                                                                             |
| -        | 2.25±0.02ms                           | 1.58±0.01ms                        |    0.7  | reshape.ReshapeExtensionDtype.time_stack('Period[s]')                                                                                                              |
| -        | 622±10μs                              | 405±2μs                            |    0.65 | frame_methods.Iteration.time_items_cached                                                                                                                          |
| -        | 16.7±0.2ms                            | 7.19±0.05ms                        |    0.43 | frame_methods.Iteration.time_items                                                                                                                                 |
| -        | 187±0.5ms                             | 74.0±1ms                           |    0.39 | groupby.Apply.time_copy_overhead_single_col(4)                                                                                                                     |
| -        | 995±6ms                               | 350±3ms                            |    0.35 | groupby.Apply.time_copy_function_multi_col(4)                                                                                                                      |
| -        | 965±5ms                               | 107±0.8ms                          |    0.11 | frame_methods.GetDtypeCounts.time_info                                                                                                                             |
| -        | 265±1ms                               | 25.7±0.03ms                        |    0.1  | frame_methods.Iteration.time_iteritems_indexing                                                     
```

</details>

From #55256 I'm now getting 1.34s with no CoW, 1.63s with.
Thx @rhshadrach appreciate you running the asvs.

So we are good here? I want to look into the groupby problem independently to see if there is something we can do 
Thanks @phofl