Commit c5ab7c9
authored
[release-1.10] dont reset maxsize in jl_array_to_string (#55689)
Let's change `jl_array_to_string` so that we make the consequences of
calling it in a thread-unsafe way less disastrous (i.e. let's avoid
corrupting GC internal metrics).
Strictly speaking, this is not a bug-fix because calling
`jl_array_to_string` concurrently from two threads is UB in any case.
To see how a race here may lead to negative `live_bytes`, consider this
MWE from @NHDaly:
- 1.10:
```Julia
julia> GC.gc(true); Base.gc_live_bytes()
1842370
julia> g_vecs = Any[
UInt8['a' for _ in 1:1000000000]
for _ in 1:10
];
julia> GC.gc(true); Base.gc_live_bytes()
10001774906
julia> Threads.@threads for _ in 1:1000
for v in g_vecs
String(v)
end
end
julia> GC.gc(true); Base.gc_live_bytes()
-1997600207
```
- This patch:
```Julia
julia> GC.gc(true); Base.gc_live_bytes()
1862440
julia> g_vecs = Any[
UInt8['a' for _ in 1:1000000000]
for _ in 1:10
];
julia> GC.gc(true); Base.gc_live_bytes()
10001796440
julia> Threads.@threads for _ in 1:1000
for v in g_vecs
String(v)
end
end
julia> GC.gc(true); Base.gc_live_bytes()
10002390952
```1 parent c7f5f2d commit c5ab7c9
3 files changed
+0
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
482 | | - | |
483 | 482 | | |
484 | 483 | | |
485 | | - | |
486 | 484 | | |
487 | 485 | | |
488 | 486 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1128 | 1128 | | |
1129 | 1129 | | |
1130 | 1130 | | |
1131 | | - | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | 1131 | | |
1139 | 1132 | | |
1140 | 1133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
576 | | - | |
577 | 576 | | |
578 | 577 | | |
579 | 578 | | |
| |||
0 commit comments