Issue: Avoid parallel redownload in cache
State: closed
Author: albertvillanova

Avoid parallel redownload in cache by retrying inside the lock if path exists.

Comments:
_The documentation is not available anymore as the PR was closed or merged._

<details>
<summary>Show benchmarks</summary>

PyArrow==8.0.0

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.006157 / 0.011353 (-0.005196) | 0.003790 / 0.011008 (-0.007219) | 0.097889 / 0.038508 (0.059381) | 0.029038 / 0.023109 (0.005929) | 0.306918 / 0.275898 (0.031020) | 0.339637 / 0.323480 (0.016157) | 0.003526 / 0.007986 (-0.004460) | 0.003102 / 0.004328 (-0.001227) | 0.076908 / 0.004250 (0.072658) | 0.039254 / 0.037052 (0.002201) | 0.309197 / 0.258489 (0.050708) | 0.345635 / 0.293841 (0.051794) | 0.027954 / 0.128546 (-0.100593) | 0.008510 / 0.075646 (-0.067136) | 0.314674 / 0.419271 (-0.104598) | 0.057102 / 0.043533 (0.013569) | 0.307495 / 0.255139 (0.052356) | 0.329501 / 0.283200 (0.046302) | 0.098450 / 0.141683 (-0.043233) | 1.480102 / 1.452155 (0.027948) | 1.550554 / 1.492716 (0.057838) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.207440 / 0.018006 (0.189434) | 0.426560 / 0.000490 (0.426071) | 0.003250 / 0.000200 (0.003050) | 0.000074 / 0.000054 (0.000019) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.023777 / 0.037411 (-0.013634) | 0.103905 / 0.014526 (0.089379) | 0.108324 / 0.176557 (-0.068233) | 0.167223 / 0.737135 (-0.569913) | 0.113529 / 0.296338 (-0.182810) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.426770 / 0.215209 (0.211561) | 4.251806 / 2.077655 (2.174151) | 2.010426 / 1.504120 (0.506306) | 1.858630 / 1.541195 (0.317435) | 1.941318 / 1.468490 (0.472828) | 0.558056 / 4.584777 (-4.026721) | 3.399107 / 3.745712 (-0.346606) | 1.758386 / 5.269862 (-3.511476) | 1.036305 / 4.565676 (-3.529372) | 0.067094 / 0.424275 (-0.357182) | 0.011167 / 0.007607 (0.003560) | 0.526705 / 0.226044 (0.300661) | 5.250319 / 2.268929 (2.981390) | 2.496723 / 55.444624 (-52.947902) | 2.154013 / 6.876477 (-4.722464) | 2.394724 / 2.142072 (0.252652) | 0.669723 / 4.805227 (-4.135504) | 0.136367 / 6.500664 (-6.364297) | 0.067080 / 0.075469 (-0.008389) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.269700 / 1.841788 (-0.572088) | 14.099775 / 8.074308 (6.025467) | 14.422936 / 10.191392 (4.231544) | 0.132344 / 0.680424 (-0.548080) | 0.016744 / 0.534201 (-0.517457) | 0.378286 / 0.579283 (-0.200997) | 0.392282 / 0.434364 (-0.042082) | 0.437648 / 0.540337 (-0.102689) | 0.528554 / 1.386936 (-0.858382) |

</details>
PyArrow==latest

<details>
<summary>Show updated benchmarks!</summary>

### Benchmark: benchmark_array_xd.json

| metric | read_batch_formatted_as_numpy after write_array2d | read_batch_formatted_as_numpy after write_flattened_sequence | read_batch_formatted_as_numpy after write_nested_sequence | read_batch_unformated after write_array2d | read_batch_unformated after write_flattened_sequence | read_batch_unformated after write_nested_sequence | read_col_formatted_as_numpy after write_array2d | read_col_formatted_as_numpy after write_flattened_sequence | read_col_formatted_as_numpy after write_nested_sequence | read_col_unformated after write_array2d | read_col_unformated after write_flattened_sequence | read_col_unformated after write_nested_sequence | read_formatted_as_numpy after write_array2d | read_formatted_as_numpy after write_flattened_sequence | read_formatted_as_numpy after write_nested_sequence | read_unformated after write_array2d | read_unformated after write_flattened_sequence | read_unformated after write_nested_sequence | write_array2d | write_flattened_sequence | write_nested_sequence |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.006086 / 0.011353 (-0.005267) | 0.003769 / 0.011008 (-0.007239) | 0.077414 / 0.038508 (0.038906) | 0.027806 / 0.023109 (0.004697) | 0.360333 / 0.275898 (0.084434) | 0.404725 / 0.323480 (0.081245) | 0.003443 / 0.007986 (-0.004543) | 0.004434 / 0.004328 (0.000106) | 0.077309 / 0.004250 (0.073059) | 0.040441 / 0.037052 (0.003388) | 0.358627 / 0.258489 (0.100138) | 0.415246 / 0.293841 (0.121405) | 0.027718 / 0.128546 (-0.100829) | 0.008495 / 0.075646 (-0.067151) | 0.082874 / 0.419271 (-0.336397) | 0.042323 / 0.043533 (-0.001210) | 0.354895 / 0.255139 (0.099756) | 0.390032 / 0.283200 (0.106832) | 0.092377 / 0.141683 (-0.049306) | 1.492817 / 1.452155 (0.040662) | 1.551859 / 1.492716 (0.059143) |

### Benchmark: benchmark_getitem\_100B.json

| metric | get_batch_of\_1024\_random_rows | get_batch_of\_1024\_rows | get_first_row | get_last_row |
|--------|---|---|---|---|
| new / old (diff) | 0.198921 / 0.018006 (0.180915) | 0.417699 / 0.000490 (0.417209) | 0.001349 / 0.000200 (0.001149) | 0.000071 / 0.000054 (0.000016) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.026349 / 0.037411 (-0.011062) | 0.105712 / 0.014526 (0.091186) | 0.111792 / 0.176557 (-0.064765) | 0.163677 / 0.737135 (-0.573459) | 0.116864 / 0.296338 (-0.179474) |

### Benchmark: benchmark_iterating.json

| metric | read 5000 | read 50000 | read_batch 50000 10 | read_batch 50000 100 | read_batch 50000 1000 | read_formatted numpy 5000 | read_formatted pandas 5000 | read_formatted tensorflow 5000 | read_formatted torch 5000 | read_formatted_batch numpy 5000 10 | read_formatted_batch numpy 5000 1000 | shuffled read 5000 | shuffled read 50000 | shuffled read_batch 50000 10 | shuffled read_batch 50000 100 | shuffled read_batch 50000 1000 | shuffled read_formatted numpy 5000 | shuffled read_formatted_batch numpy 5000 10 | shuffled read_formatted_batch numpy 5000 1000 |
|--------|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 0.447532 / 0.215209 (0.232323) | 4.468770 / 2.077655 (2.391116) | 2.403820 / 1.504120 (0.899700) | 2.273640 / 1.541195 (0.732445) | 2.337505 / 1.468490 (0.869015) | 0.560729 / 4.584777 (-4.024048) | 3.389165 / 3.745712 (-0.356547) | 2.697614 / 5.269862 (-2.572247) | 1.351909 / 4.565676 (-3.213768) | 0.068089 / 0.424275 (-0.356186) | 0.011639 / 0.007607 (0.004032) | 0.555277 / 0.226044 (0.329233) | 5.559291 / 2.268929 (3.290363) | 2.657609 / 55.444624 (-52.787015) | 2.346667 / 6.876477 (-4.529809) | 2.615823 / 2.142072 (0.473751) | 0.668662 / 4.805227 (-4.136566) | 0.136593 / 6.500664 (-6.364071) | 0.068384 / 0.075469 (-0.007085) |

### Benchmark: benchmark_map_filter.json

| metric | filter | map fast-tokenizer batched | map identity | map identity batched | map no-op batched | map no-op batched numpy | map no-op batched pandas | map no-op batched pytorch | map no-op batched tensorflow |
|--------|---|---|---|---|---|---|---|---|---|
| new / old (diff) | 1.312089 / 1.841788 (-0.529699) | 14.477510 / 8.074308 (6.403202) | 14.231432 / 10.191392 (4.040040) | 0.132015 / 0.680424 (-0.548409) | 0.016908 / 0.534201 (-0.517293) | 0.368315 / 0.579283 (-0.210968) | 0.397964 / 0.434364 (-0.036400) | 0.432446 / 0.540337 (-0.107891) | 0.526349 / 1.386936 (-0.860587) |

</details>
</details>

![](https://cml.dev/watermark.png#78b4d55c3cfc60e309eb033d3ed0aba5e796b6ce "CML watermark")