From 0c10e237d319166c98c810c0d03179e14ab55213 Mon Sep 17 00:00:00 2001 From: fang Date: Tue, 3 Nov 2020 19:17:13 +0100 Subject: [PATCH 1/2] verb: render printouts lazily Instead of passing in a tape to print in case we need in, pass in a trap that can be called to generate the tape on-demand. Eagerly rendering printouts was costing us a lot of time when we didn't actually need them, because the pretty-printer is slow. --- pkg/arvo/lib/verb.hoon | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/arvo/lib/verb.hoon b/pkg/arvo/lib/verb.hoon index ead541ef9..dc3bf7b37 100644 --- a/pkg/arvo/lib/verb.hoon +++ b/pkg/arvo/lib/verb.hoon @@ -12,26 +12,26 @@ :: ++ on-init ^- (quip card:agent:gall agent:gall) - %- (print bowl "{}: on-init") + %- (print bowl |.("{}: on-init")) =^ cards agent on-init:ag [[(emit-event %on-init ~) cards] this] :: ++ on-save ^- vase - %- (print bowl "{}: on-save") + %- (print bowl |.("{}: on-save")) on-save:ag :: ++ on-load |= old-state=vase ^- (quip card:agent:gall agent:gall) - %- (print bowl "{}: on-load") + %- (print bowl |.("{}: on-load")) =^ cards agent (on-load:ag old-state) [[(emit-event %on-load ~) cards] this] :: ++ on-poke |= [=mark =vase] ^- (quip card:agent:gall agent:gall) - %- (print bowl "{}: on-poke with mark {}") + %- (print bowl |.("{}: on-poke with mark {}")) ?: ?=(%verb mark) ?- !<(?(%loud %bowl) vase) %loud `this(loud !loud) @@ -43,7 +43,7 @@ ++ on-watch |= =path ^- (quip card:agent:gall agent:gall) - %- (print bowl "{}: on-watch on path {}") + %- (print bowl |.("{}: on-watch on path {}")) =^ cards agent ?: ?=([%verb %events ~] path) [~ agent] @@ -53,7 +53,7 @@ ++ on-leave |= =path ^- (quip card:agent:gall agent:gall) - %- (print bowl "{}: on-leave on path {}") + %- (print bowl |.("{}: on-leave on path {}")) ?: ?=([%verb %event ~] path) [~ this] =^ cards agent (on-leave:ag path) @@ -62,39 +62,40 @@ ++ on-peek |= =path ^- (unit (unit cage)) - %- (print bowl "{}: on-peek on path {}") + %- (print bowl |.("{}: on-peek on path {}")) (on-peek:ag path) :: ++ on-agent |= [=wire =sign:agent:gall] ^- (quip card:agent:gall agent:gall) - %- (print bowl "{}: on-agent on wire {}, {<-.sign>}") + %- (print bowl |.("{}: on-agent on wire {}, {<-.sign>}")) =^ cards agent (on-agent:ag wire sign) [[(emit-event %on-agent wire -.sign) cards] this] :: ++ on-arvo |= [=wire =sign-arvo] ^- (quip card:agent:gall agent:gall) - %- (print bowl "{}: on-arvo on wire {}, {<[- +<]:sign-arvo>}") + %- %+ print bowl |. + "{}: on-arvo on wire {}, {<[- +<]:sign-arvo>}" =^ cards agent (on-arvo:ag wire sign-arvo) [[(emit-event %on-arvo wire [- +<]:sign-arvo) cards] this] :: ++ on-fail |= [=term =tang] ^- (quip card:agent:gall agent:gall) - %- (print bowl "{}: on-fail with term {}") + %- (print bowl |.("{}: on-fail with term {}")) =^ cards agent (on-fail:ag term tang) [[(emit-event %on-fail term) cards] this] -- :: ++ print - |= [=bowl:gall =tape] + |= [=bowl:gall tape=_^?(|.(*tape))] ^+ same =? . bowl-print %- (slog >bowl< ~) . ?. loud same - %- (slog leaf+tape ~) + %- (slog leaf+(tape) ~) same :: ++ emit-event From a94c63d4121089d3de08ba1e5392578952d2b063 Mon Sep 17 00:00:00 2001 From: fang Date: Tue, 3 Nov 2020 20:15:58 +0100 Subject: [PATCH 2/2] verb: improve code style in +print --- pkg/arvo/lib/verb.hoon | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/arvo/lib/verb.hoon b/pkg/arvo/lib/verb.hoon index dc3bf7b37..2737addfc 100644 --- a/pkg/arvo/lib/verb.hoon +++ b/pkg/arvo/lib/verb.hoon @@ -89,13 +89,13 @@ -- :: ++ print - |= [=bowl:gall tape=_^?(|.(*tape))] + |= [=bowl:gall render=(trap tape)] ^+ same =? . bowl-print %- (slog >bowl< ~) . ?. loud same - %- (slog leaf+(tape) ~) + %- (slog [%leaf $:render] ~) same :: ++ emit-event