mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-30 10:31:47 +00:00
make ORC threadlocal, take two (#21818)
* ORC: make rootsThreshold thread local [backport]
* fixes the regression
(cherry picked from commit f3a4cc584e)
This commit is contained in:
@@ -348,7 +348,7 @@ const
|
||||
when defined(nimStressOrc):
|
||||
const rootsThreshold = 10 # broken with -d:nimStressOrc: 10 and for havlak iterations 1..8
|
||||
else:
|
||||
var rootsThreshold = defaultThreshold
|
||||
var rootsThreshold {.threadvar.}: int
|
||||
|
||||
proc partialCollect(lowMark: int) =
|
||||
when false:
|
||||
@@ -390,16 +390,16 @@ proc collectCycles() =
|
||||
# of the cycle collector's effectiveness:
|
||||
# we're effective when we collected 50% or more of the nodes
|
||||
# we touched. If we're effective, we can reset the threshold:
|
||||
if j.keepThreshold and rootsThreshold <= defaultThreshold:
|
||||
if j.keepThreshold:
|
||||
discard
|
||||
elif j.freed * 2 >= j.touched:
|
||||
when not defined(nimFixedOrc):
|
||||
rootsThreshold = max(rootsThreshold div 3 * 2, 16)
|
||||
else:
|
||||
rootsThreshold = defaultThreshold
|
||||
rootsThreshold = 0
|
||||
#cfprintf(cstderr, "[collectCycles] freed %ld, touched %ld new threshold %ld\n", j.freed, j.touched, rootsThreshold)
|
||||
elif rootsThreshold < high(int) div 4:
|
||||
rootsThreshold = rootsThreshold * 3 div 2
|
||||
rootsThreshold = (if rootsThreshold <= 0: defaultThreshold else: rootsThreshold) * 3 div 2
|
||||
when logOrc:
|
||||
cfprintf(cstderr, "[collectCycles] end; freed %ld new threshold %ld touched: %ld mem: %ld rcSum: %ld edges: %ld\n", j.freed, rootsThreshold, j.touched,
|
||||
getOccupiedMem(), j.rcSum, j.edges)
|
||||
@@ -409,7 +409,7 @@ proc registerCycle(s: Cell; desc: PNimTypeV2) =
|
||||
if roots.d == nil: init(roots)
|
||||
add(roots, s, desc)
|
||||
|
||||
if roots.len >= rootsThreshold:
|
||||
if roots.len >= rootsThreshold+defaultThreshold:
|
||||
collectCycles()
|
||||
when logOrc:
|
||||
writeCell("[added root]", s, desc)
|
||||
@@ -424,7 +424,7 @@ proc GC_enableOrc*() =
|
||||
## Enables the cycle collector subsystem of `--gc:orc`. This is a `--gc:orc`
|
||||
## specific API. Check with `when defined(gcOrc)` for its existence.
|
||||
when not defined(nimStressOrc):
|
||||
rootsThreshold = defaultThreshold
|
||||
rootsThreshold = 0
|
||||
|
||||
proc GC_disableOrc*() =
|
||||
## Disables the cycle collector subsystem of `--gc:orc`. This is a `--gc:orc`
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
discard """
|
||||
outputsub: "(allocCount: 4302, deallocCount: 4300)"
|
||||
outputsub: "(allocCount: 4050, deallocCount: 4048)"
|
||||
cmd: "nim c --gc:orc -d:nimAllocStats $file"
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user