From 979ebcf91705709be5041a3be4514e5f1f6ec02c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 28 Feb 2017 23:58:15 +0000 Subject: unicorn_http: reduce rb_global_variable calls rb_global_variable registers the address of the variable which refers to the object, instead of the object itself. This adds extra overhead to each global variable for our case, where the variable is frozen and never changed. Given there are currently 59 elements in this array, this saves 58 singly-linked list entries and associated malloc calls and associated overhead in the current mainline Ruby 2.x implementation. On 64-bit GNU libc malloc, this is already 16 * 58 = 928 bytes; more than the extra object slot and array slack space used by the new mark array. Mainline Ruby 1.9+ currently has a rb_gc_register_mark_object public function which would suite our needs, too, but it is currently undocumented, and may not be available in the future. --- ext/unicorn_http/global_variables.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/unicorn_http/global_variables.h') diff --git a/ext/unicorn_http/global_variables.h b/ext/unicorn_http/global_variables.h index e1c43c9..c17ee6a 100644 --- a/ext/unicorn_http/global_variables.h +++ b/ext/unicorn_http/global_variables.h @@ -56,7 +56,7 @@ NORETURN(static void parser_raise(VALUE klass, const char *)); /** Defines global strings in the init method. */ #define DEF_GLOBAL(N, val) do { \ g_##N = rb_obj_freeze(rb_str_new(val, sizeof(val) - 1)); \ - rb_global_variable(&g_##N); \ + rb_ary_push(mark_ary, g_##N); \ } while (0) /* Defines the maximum allowed lengths for various input elements.*/ @@ -67,7 +67,7 @@ DEF_MAX_LENGTH(FRAGMENT, 1024); /* Don't know if this length is specified somewh DEF_MAX_LENGTH(REQUEST_PATH, 4096); /* common PATH_MAX on modern systems */ DEF_MAX_LENGTH(QUERY_STRING, (1024 * 10)); -static void init_globals(void) +static void init_globals(VALUE mark_ary) { DEF_GLOBAL(rack_url_scheme, "rack.url_scheme"); DEF_GLOBAL(request_method, "REQUEST_METHOD"); -- cgit v1.2.3-24-ge0c7