From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 837462013A for ; Wed, 15 Feb 2017 22:32:36 +0000 (UTC) From: Eric Wong To: clogger-public@bogomips.org Subject: [PATCH] ext: reduce frozen string marking overhead Date: Wed, 15 Feb 2017 22:32:36 +0000 Message-Id: <20170215223236.25484-1-e@80x24.org> List-Id: Using rb_global_variable excessively can be expensive since it uses a singly-linked list to track addresses. Since these strings are all frozen and constant, put them into an array instead and only mark the array as a global to improve locality. Ruby 1.9+ has rb_gc_register_mark_object but it is not part of the documented, public API, so we're not using it, yet. --- ext/clogger_ext/clogger.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index 83ce76a..481dd61 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -29,6 +29,7 @@ * under. */ static clockid_t hopefully_CLOCK_MONOTONIC; +static VALUE mark_ary; static void check_clock(void) { @@ -949,7 +950,7 @@ static VALUE clogger_init_copy(VALUE clone, VALUE orig) #define CONST_GLOBAL_STR2(var, val) do { \ g_##var = rb_obj_freeze(rb_str_new(val, sizeof(val) - 1)); \ - rb_global_variable(&g_##var); \ + rb_ary_push(mark_ary, g_##var); \ } while (0) #define CONST_GLOBAL_STR(val) CONST_GLOBAL_STR2(val, #val) @@ -1015,6 +1016,9 @@ void Init_clogger_ext(void) { VALUE tmp; + mark_ary = rb_ary_new(); + rb_global_variable(&mark_ary); + check_clock(); write_id = rb_intern("write"); @@ -1060,4 +1064,6 @@ void Init_clogger_ext(void) tmp = rb_const_get(rb_cObject, rb_intern("Rack")); tmp = rb_const_get(tmp, rb_intern("Utils")); cHeaderHash = rb_const_get(tmp, rb_intern("HeaderHash")); + + rb_obj_freeze(mark_ary); } -- EW