about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-06-05 20:43:39 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-06-05 20:43:39 -0700
commit0b3d456f2cba50b14664f268c100d643f3119690 (patch)
treef553e63fb4ed22a34a0daeb28f0126c7a64bce98
parentb012fba1bcc37f2747b5295dd547cb6eefe5caa5 (diff)
downloadmu-0b3d456f2cba50b14664f268c100d643f3119690.tar.gz
clean up a large memory leak
It turns out (bowboard screen 128) on a real screen massively slowed down
and ran out of memory since commit e2ab1b30b1 on May 19. The culprit was
these changes, which created memory allocations for a new trace on every
recursive call.

I originally had some vague desire to isolate these calls from the user-visible
trace. That's expensive enough that I'll wait until it becomes a concern
before trying to isolate again.
-rw-r--r--shell/data.limg2
-rw-r--r--shell/evaluate.mu21
2 files changed, 7 insertions, 16 deletions
diff --git a/shell/data.limg b/shell/data.limg
index ae5c2f4d..de093dee 100644
--- a/shell/data.limg
+++ b/shell/data.limg
@@ -126,7 +126,7 @@
     (for x r (< x xmax) (+= x side)
       (circle_rainbow screen x y (- r 100) 10)))))))])
     (main . [(def (main screen keyboard)
-  (circle_rainbow screen 90 90 8 1))])
+  (bowboard screen 128))])
   ))
   (sandbox . (+ 3 4))
 )
diff --git a/shell/evaluate.mu b/shell/evaluate.mu
index 8ad89795..3de0f1eb 100644
--- a/shell/evaluate.mu
+++ b/shell/evaluate.mu
@@ -886,12 +886,7 @@ fn lookup-symbol sym: (addr cell), out: (addr handle cell), env-h: (handle cell)
   # check car
   var env-head-storage: (handle cell)
   var env-head-ah/eax: (addr handle cell) <- address env-head-storage
-  {
-    var nested-trace-storage: trace
-    var nested-trace/edi: (addr trace) <- address nested-trace-storage
-    initialize-trace nested-trace, 1/only-errors, 0x10/capacity, 0/visible
-    car env, env-head-ah, nested-trace
-  }
+  car env, env-head-ah, trace
   var _env-head/eax: (addr cell) <- lookup *env-head-ah
   var env-head/ecx: (addr cell) <- copy _env-head
   # if car is not a list, abort
@@ -922,10 +917,7 @@ fn lookup-symbol sym: (addr cell), out: (addr handle cell), env-h: (handle cell)
   compare match?, 0/false
   {
     break-if-=
-    var nested-trace-storage: trace
-    var nested-trace/edi: (addr trace) <- address nested-trace-storage
-    initialize-trace nested-trace, 1/only-errors, 0x10/capacity, 0/visible
-    cdr env-head, out, nested-trace
+    cdr env-head, out, trace
     # trace "=> " out " (match)" {{{
     {
       var should-trace?/eax: boolean <- should-trace? trace
@@ -937,7 +929,9 @@ fn lookup-symbol sym: (addr cell), out: (addr handle cell), env-h: (handle cell)
       var stream-storage: (stream byte 0x800)
       var stream/ecx: (addr stream byte) <- address stream-storage
       write stream, "=> "
-      clear-trace nested-trace
+      var nested-trace-storage: trace
+      var nested-trace/edi: (addr trace) <- address nested-trace-storage
+      initialize-trace nested-trace, 1/only-errors, 0x10/capacity, 0/visible
       print-cell out, stream, nested-trace
       write stream, " (match)"
       trace trace, "eval", stream
@@ -1098,10 +1092,7 @@ fn mutate-binding name: (addr stream byte), val: (addr handle cell), env-h: (han
   # check car
   var env-head-storage: (handle cell)
   var env-head-ah/eax: (addr handle cell) <- address env-head-storage
-  var nested-trace-storage: trace
-  var nested-trace/edi: (addr trace) <- address nested-trace-storage
-  initialize-trace nested-trace, 1/only-errors, 0x10/capacity, 0/visible
-  car env, env-head-ah, nested-trace
+  car env, env-head-ah, trace
   var _env-head/eax: (addr cell) <- lookup *env-head-ah
   var env-head/ecx: (addr cell) <- copy _env-head
   # if car is not a list, abort