From ac880411d4455a23b3cec8c26b0d5ae96e880114 Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Sat, 24 Oct 2015 01:27:56 -0400 Subject: [PATCH] Memoize the Un constructor for unions This seems to speed up typechecking by 5-10% (depending on the machine) on compiling the math library and on the "new-metrics.rkt" test. --- typed-racket-lib/typed-racket/types/union.rkt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/typed-racket-lib/typed-racket/types/union.rkt b/typed-racket-lib/typed-racket/types/union.rkt index 16b7b7d4..00c1f322 100644 --- a/typed-racket-lib/typed-racket/types/union.rkt +++ b/typed-racket-lib/typed-racket/types/union.rkt @@ -49,11 +49,16 @@ ;; Normalizes representation by sorting types. ;; Type * -> Type ;; The input types can overlap and be union types +(define Un-cache (make-weak-hash)) (define Un (case-lambda [() -Bottom] [(t) t] [args - (define ts (foldr merge '() - (remove-dups (sort (append-map flat args) type