summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-03-21 23:10:56 +0100
committerAraq <rumpf_a@web.de>2012-03-21 23:10:56 +0100
commit03ba0f3e251a08587a12a340949bb2de49178af9 (patch)
tree07639d78726758330b87ee106b4a12ad3cd553ee /lib/system
parentbb1885115db4d8075a6c688b58d4ccb91b6ad24a (diff)
downloadNim-03ba0f3e251a08587a12a340949bb2de49178af9.tar.gz
implemented marker procs for the GC resulting in huge speedups
Diffstat (limited to 'lib/system')
-rwxr-xr-xlib/system/gc.nim29
-rwxr-xr-xlib/system/hti.nim1
2 files changed, 19 insertions, 11 deletions
diff --git a/lib/system/gc.nim b/lib/system/gc.nim
index f01e9c04a..af54fe350 100755
--- a/lib/system/gc.nim
+++ b/lib/system/gc.nim
@@ -338,17 +338,21 @@ proc forAllChildren(cell: PCell, op: TWalkOp) =
   sysAssert(cell != nil, "forAllChildren: 1")
   sysAssert(cell.typ != nil, "forAllChildren: 2")
   sysAssert cell.typ.kind in {tyRef, tySequence, tyString}, "forAllChildren: 3"
-  case cell.typ.Kind
-  of tyRef: # common case
-    forAllChildrenAux(cellToUsr(cell), cell.typ.base, op)
-  of tySequence:
-    var d = cast[TAddress](cellToUsr(cell))
-    var s = cast[PGenericSeq](d)
-    if s != nil:
-      for i in 0..s.len-1:
-        forAllChildrenAux(cast[pointer](d +% i *% cell.typ.base.size +%
-          GenericSeqSize), cell.typ.base, op)
-  else: nil
+  let marker = cell.typ.marker
+  if marker != nil:
+    marker(cellToUsr(cell), op.int)
+  else:
+    case cell.typ.Kind
+    of tyRef: # common case
+      forAllChildrenAux(cellToUsr(cell), cell.typ.base, op)
+    of tySequence:
+      var d = cast[TAddress](cellToUsr(cell))
+      var s = cast[PGenericSeq](d)
+      if s != nil:
+        for i in 0..s.len-1:
+          forAllChildrenAux(cast[pointer](d +% i *% cell.typ.base.size +%
+            GenericSeqSize), cell.typ.base, op)
+    else: nil
 
 proc addNewObjToZCT(res: PCell, gch: var TGcHeap) {.inline.} =
   # we check the last 8 entries (cache line) for a slot that could be reused.
@@ -528,6 +532,9 @@ proc doOperation(p: pointer, op: TWalkOp) =
     sysAssert(c.refcount >=% rcIncrement, "doOperation 3")
     c.refcount = c.refcount -% rcIncrement
 
+proc nimGCvisit(d: pointer, op: int) {.compilerProc.} =
+  doOperation(d, TWalkOp(op))
+
 # we now use a much simpler and non-recursive algorithm for cycle removal
 proc collectCycles(gch: var TGcHeap) =
   var tabSize = 0
diff --git a/lib/system/hti.nim b/lib/system/hti.nim
index 776a4d2c2..1d62b910a 100755
--- a/lib/system/hti.nim
+++ b/lib/system/hti.nim
@@ -60,6 +60,7 @@ type # This should be he same as ast.TTypeKind
     base: ptr TNimType
     node: ptr TNimNode # valid for tyRecord, tyObject, tyTuple, tyEnum
     finalizer: pointer # the finalizer for the type
+    marker: proc (p: pointer, op: int) # marker proc for GC
   PNimType = ptr TNimType
   
 # node.len may be the ``first`` element of a set