equal
deleted
inserted
replaced
15 |
15 |
16 (define (by-immutable) |
16 (define (by-immutable) |
17 (define f (eval '(lambda (x) (+ x 1)) ns)) |
17 (define f (eval '(lambda (x) (+ x 1)) ns)) |
18 (for/fold [(x 0)] [(n (in-range N))] (f x))) |
18 (for/fold [(x 0)] [(n (in-range N))] (f x))) |
19 |
19 |
20 (for [(i 5)] (time (by-immutable))) |
20 ;; (printf "by-immutable\n") |
21 (newline) |
21 ;; (for [(i 5)] (time (by-immutable))) |
|
22 ;; (newline) |
22 |
23 |
23 (define (by-unboxing) |
24 (define (by-unboxing) |
24 (define f (eval '(box (lambda (x) (+ x 1))) ns)) |
25 (define f (eval '(box (lambda (x) (+ x 1))) ns)) |
25 (for/fold [(x 0)] [(n (in-range N))] ((unbox f) x))) |
26 (for/fold [(x 0)] [(n (in-range N))] ((unbox f) x))) |
26 |
27 |
|
28 (printf "by-unboxing\n") |
27 (for [(i 5)] (time (by-unboxing))) |
29 (for [(i 5)] (time (by-unboxing))) |
28 (newline) |
30 (newline) |
29 |
31 |
30 (define (by-embedding) |
32 (define (by-embedding) |
31 (define f (eval '(let ((inner-f (lambda (x) (+ x 1)))) |
33 (define f (eval '(let ((inner-f (lambda (x) (+ x 1)))) |
33 [() (lambda (new-f) (set! inner-f new-f))] |
35 [() (lambda (new-f) (set! inner-f new-f))] |
34 [(x) (inner-f x)])) |
36 [(x) (inner-f x)])) |
35 ns)) |
37 ns)) |
36 (for/fold [(x 0)] [(n (in-range N))] (f x))) |
38 (for/fold [(x 0)] [(n (in-range N))] (f x))) |
37 |
39 |
38 (for [(i 5)] (time (by-embedding))) |
40 ;; (printf "by-embedding\n") |
39 (newline) |
41 ;; (for [(i 5)] (time (by-embedding))) |
|
42 ;; (newline) |
40 |
43 |
41 (define (by-unboxing-with-check) |
44 (define (by-unboxing-with-check) |
42 (define f (eval `(letrec ((b (box (lambda (x) |
45 (define f (eval `(letrec ((b (box (lambda (x) |
43 (if (> epoch ,epoch) |
46 (if (> epoch ,epoch) |
44 (begin (set-box! b (lambda (x) (+ x 2))) |
47 (begin (set-box! b (lambda (x) (+ x 2))) |
46 (+ x 1)))))) |
49 (+ x 1)))))) |
47 b) |
50 b) |
48 ns)) |
51 ns)) |
49 (for/fold [(x 0)] [(n (in-range N))] ((unbox f) x))) |
52 (for/fold [(x 0)] [(n (in-range N))] ((unbox f) x))) |
50 |
53 |
|
54 (printf "by-unboxing-with-check\n") |
51 (for [(i 5)] (time (by-unboxing-with-check))) |
55 (for [(i 5)] (time (by-unboxing-with-check))) |
|
56 (newline) |
|
57 |
|
58 ;; TODO: Experiment with hoisting the check out to being on the send |
|
59 ;; side, rather than the receive side; also consider the idea that |
|
60 ;; when inlining/partially-evaluating, probably want to residualize |
|
61 ;; the epoch check for each inlined method! If there's a separate |
|
62 ;; epoch for each method, that is. (If there's a global epoch, |
|
63 ;; everything gets invalidated at once, and the check just needs to |
|
64 ;; live at the top of each method - or every box has to be |
|
65 ;; discoverable and updateable.) Ultimately, there's some |
|
66 ;; interesting interaction between the source-ish forms of the |
|
67 ;; method and the target-ish forms of the method here. |
|
68 (define (by-unboxing-with-check-but-no-fixed-box) |
|
69 (define f (eval `(box (lambda (b x) |
|
70 (if (> epoch ,epoch) |
|
71 (begin (set-box! b (lambda (x) (+ x 2))) |
|
72 ((unbox b) b x)) |
|
73 (+ x 1)))) |
|
74 ns)) |
|
75 (for/fold [(x 0)] [(n (in-range N))] ((unbox f) f x))) |
|
76 |
|
77 (printf "by-unboxing-with-check-but-no-fixed-box\n") |
|
78 (for [(i 5)] (time (by-unboxing-with-check-but-no-fixed-box))) |
52 (newline) |
79 (newline) |
53 |
80 |
54 ) |
81 ) |
55 |
82 |
56 (module+ main (main)) |
83 (module+ main (main)) |