From e7dc3815de8e51f0f2f1b14fd3c7a5879a02115a Mon Sep 17 00:00:00 2001 From: "Sunrin SHIMURA (keen)" <3han5chou7@gmail.com> Date: Sun, 4 Jan 2015 04:59:42 +0000 Subject: [PATCH 1/2] Merge commit '2440372c16fd1e479ad8aa346f6006dbf795a74c' into restore-config --- include/picrin/config.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/picrin/config.h b/include/picrin/config.h index 76c30066..889e268b 100644 --- a/include/picrin/config.h +++ b/include/picrin/config.h @@ -58,11 +58,11 @@ #endif #ifndef PIC_ARENA_SIZE -# define PIC_ARENA_SIZE 1000 +# define PIC_ARENA_SIZE (8 * 1024) #endif #ifndef PIC_HEAP_PAGE_SIZE -# define PIC_HEAP_PAGE_SIZE 10000 +# define PIC_HEAP_PAGE_SIZE (2 * 1024 * 1024) #endif #ifndef PIC_STACK_SIZE @@ -74,7 +74,7 @@ #endif #ifndef PIC_SYM_POOL_SIZE -# define PIC_SYM_POOL_SIZE 128 +# define PIC_SYM_POOL_SIZE (2 * 1024) #endif #ifndef PIC_IREP_SIZE From 311fb62474085520d09069b6b5d74b9afd8e404f Mon Sep 17 00:00:00 2001 From: "Sunrin SHIMURA (keen)" <3han5chou7@gmail.com> Date: Mon, 12 Jan 2015 11:33:22 +0000 Subject: [PATCH 2/2] optimize `equal?`. Don't initialize xhash until it is really needed. `make test-r7rs` gets 12s -> 9.5s, in which `equal?` is heavilly used. --- bool.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/bool.c b/bool.c index 8f8c75f1..0b196f51 100644 --- a/bool.c +++ b/bool.c @@ -32,7 +32,7 @@ blob_equal_p(struct pic_blob *blob1, struct pic_blob *blob2) } static bool -internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash *ht) +internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash *xh, bool xh_initted_p) { pic_value local = pic_nil_value(); size_t c; @@ -42,10 +42,15 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash * pic_errorf(pic, "Stack overflow in equal\n"); } if (pic_pair_p(x) || pic_vec_p(x)) { - if (xh_get_ptr(ht, pic_obj_ptr(x)) != NULL) { + if (! xh_initted_p) { + xh_init_ptr(xh, 0); + xh_initted_p = true; + } + + if (xh_get_ptr(xh, pic_obj_ptr(x)) != NULL) { return true; /* `x' was seen already. */ } else { - xh_put_ptr(ht, pic_obj_ptr(x), NULL); + xh_put_ptr(xh, pic_obj_ptr(x), NULL); } } } @@ -71,7 +76,7 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash * if (pic_nil_p(local)) { local = x; } - if (internal_equal_p(pic, pic_car(pic, x), pic_car(pic, y), depth + 1, ht)) { + if (internal_equal_p(pic, pic_car(pic, x), pic_car(pic, y), depth + 1, xh, xh_initted_p)) { x = pic_cdr(pic, x); y = pic_cdr(pic, y); @@ -100,7 +105,7 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash * return false; } for (i = 0; i < u->len; ++i) { - if (! internal_equal_p(pic, u->data[i], v->data[i], depth + 1, ht)) + if (! internal_equal_p(pic, u->data[i], v->data[i], depth + 1, xh, xh_initted_p)) return false; } return true; @@ -111,12 +116,11 @@ internal_equal_p(pic_state *pic, pic_value x, pic_value y, size_t depth, xhash * } bool -pic_equal_p(pic_state *pic, pic_value x, pic_value y){ +pic_equal_p(pic_state *pic, pic_value x, pic_value y) +{ xhash ht; - xh_init_ptr(&ht, 0); - - return internal_equal_p(pic, x, y, 0, &ht); + return internal_equal_p(pic, x, y, 0, &ht, false); } static pic_value