More bm-box.rkt
authorTony Garnock-Jones <tonygarnockjones@gmail.com>
Tue, 17 Jul 2018 14:04:41 +0100
changeset 393 a8aa9b77e495
parent 392 618244a1ee07
child 394 97ec29b53c47
More bm-box.rkt
experiments/little-smalltalk/bm-box.rkt
--- a/experiments/little-smalltalk/bm-box.rkt	Tue Jul 17 13:49:47 2018 +0100
+++ b/experiments/little-smalltalk/bm-box.rkt	Tue Jul 17 14:04:41 2018 +0100
@@ -17,13 +17,15 @@
     (define f (eval '(lambda (x) (+ x 1)) ns))
     (for/fold [(x 0)] [(n (in-range N))] (f x)))
 
-  (for [(i 5)] (time (by-immutable)))
-  (newline)
+  ;; (printf "by-immutable\n")
+  ;; (for [(i 5)] (time (by-immutable)))
+  ;; (newline)
 
   (define (by-unboxing)
     (define f (eval '(box (lambda (x) (+ x 1))) ns))
     (for/fold [(x 0)] [(n (in-range N))] ((unbox f) x)))
 
+  (printf "by-unboxing\n")
   (for [(i 5)] (time (by-unboxing)))
   (newline)
 
@@ -35,8 +37,9 @@
                     ns))
     (for/fold [(x 0)] [(n (in-range N))] (f x)))
 
-  (for [(i 5)] (time (by-embedding)))
-  (newline)
+  ;; (printf "by-embedding\n")
+  ;; (for [(i 5)] (time (by-embedding)))
+  ;; (newline)
 
   (define (by-unboxing-with-check)
     (define f (eval `(letrec ((b (box (lambda (x)
@@ -48,9 +51,33 @@
                     ns))
     (for/fold [(x 0)] [(n (in-range N))] ((unbox f) x)))
 
+  (printf "by-unboxing-with-check\n")
   (for [(i 5)] (time (by-unboxing-with-check)))
   (newline)
 
+  ;; TODO: Experiment with hoisting the check out to being on the send
+  ;; side, rather than the receive side; also consider the idea that
+  ;; when inlining/partially-evaluating, probably want to residualize
+  ;; the epoch check for each inlined method! If there's a separate
+  ;; epoch for each method, that is. (If there's a global epoch,
+  ;; everything gets invalidated at once, and the check just needs to
+  ;; live at the top of each method - or every box has to be
+  ;; discoverable and updateable.) Ultimately, there's some
+  ;; interesting interaction between the source-ish forms of the
+  ;; method and the target-ish forms of the method here.
+  (define (by-unboxing-with-check-but-no-fixed-box)
+    (define f (eval `(box (lambda (b x)
+                            (if (> epoch ,epoch)
+                                (begin (set-box! b (lambda (x) (+ x 2)))
+                                       ((unbox b) b x))
+                                (+ x 1))))
+                    ns))
+    (for/fold [(x 0)] [(n (in-range N))] ((unbox f) f x)))
+
+  (printf "by-unboxing-with-check-but-no-fixed-box\n")
+  (for [(i 5)] (time (by-unboxing-with-check-but-no-fixed-box)))
+  (newline)
+
   )
 
 (module+ main (main))