Kouhei Sutou
null+****@clear*****
Tue May 12 20:01:55 JST 2015
Kouhei Sutou 2015-05-12 20:01:55 +0900 (Tue, 12 May 2015) New Revision: 2bdfe0378ff55c63ca49b564def5ba14f55fe935 https://github.com/groonga/groonga/commit/2bdfe0378ff55c63ca49b564def5ba14f55fe935 Message: Reduce getenv() in each grn_ii_cursor_set_min() This fixes performance regression on Windows. getenv() is too slow on Windows. grn_ii_cursor_set_min() is called many times. So search with inverted index was very slow on Windows. Modified files: lib/ctx.c lib/grn_ii.h lib/ii.c Modified: lib/ctx.c (+6 -0) =================================================================== --- lib/ctx.c 2015-05-12 12:28:16 +0900 (765559f) +++ lib/ctx.c 2015-05-12 20:01:55 +0900 (6887e7e) @@ -21,6 +21,7 @@ #include "grn_request_canceler.h" #include "grn_tokenizers.h" #include "grn_ctx_impl.h" +#include "grn_ii.h" #include "grn_pat.h" #include "grn_plugin.h" #include "grn_snip.h" @@ -901,6 +902,10 @@ grn_init(void) GRN_LOG(ctx, GRN_LOG_ALERT, "io initialize failed (%d)", rc); return rc; } + if ((rc = grn_ii_init())) { + GRN_LOG(ctx, GRN_LOG_ALERT, "ii initialize failed (%d)", rc); + return rc; + } if ((rc = grn_plugins_init())) { GRN_LOG(ctx, GRN_LOG_ALERT, "plugins initialize failed (%d)", rc); return rc; @@ -1017,6 +1022,7 @@ grn_fin(void) grn_tokenizers_fin(); grn_normalizer_fin(); grn_plugins_fin(); + grn_ii_fin(); grn_io_fin(); grn_ctx_fin(ctx); grn_com_fin(); Modified: lib/grn_ii.h (+3 -0) =================================================================== --- lib/grn_ii.h 2015-05-12 12:28:16 +0900 (fe9b1ec) +++ lib/grn_ii.h 2015-05-12 20:01:55 +0900 (fcefd48) @@ -87,6 +87,9 @@ struct _grn_ii_updspec { typedef struct _grn_ii_updspec grn_ii_updspec; +grn_rc grn_ii_init(void); +grn_rc grn_ii_fin(void); + GRN_API grn_ii *grn_ii_create(grn_ctx *ctx, const char *path, grn_obj *lexicon, uint32_t flags); GRN_API grn_ii *grn_ii_open(grn_ctx *ctx, const char *path, grn_obj *lexicon); Modified: lib/ii.c (+40 -17) =================================================================== --- lib/ii.c 2015-05-12 12:28:16 +0900 (6f6a0ca) +++ lib/ii.c 2015-05-12 20:01:55 +0900 (beacc13) @@ -74,6 +74,44 @@ # define S_IWUSR 0200 #endif /* S_IWUSR */ +static grn_bool grn_ii_cursor_set_min_enable = GRN_FALSE; +static double grn_ii_select_too_many_index_match_ratio = -1; + +grn_rc +grn_ii_init(void) +{ + { + char grn_ii_cursor_set_min_enable_env[GRN_ENV_BUFFER_SIZE]; + grn_getenv("GRN_II_CURSOR_SET_MIN_ENABLE", + grn_ii_cursor_set_min_enable_env, + GRN_ENV_BUFFER_SIZE); + if (grn_ii_cursor_set_min_enable_env[0]) { + grn_ii_cursor_set_min_enable = GRN_TRUE; + } else { + grn_ii_cursor_set_min_enable = GRN_FALSE; + } + } + + { + char grn_ii_select_too_many_index_match_ratio_env[GRN_ENV_BUFFER_SIZE]; + grn_getenv("GRN_II_SELECT_TOO_MANY_INDEX_MATCH_RATIO", + grn_ii_select_too_many_index_match_ratio_env, + GRN_ENV_BUFFER_SIZE); + if (grn_ii_select_too_many_index_match_ratio_env[0]) { + grn_ii_select_too_many_index_match_ratio = + atof(grn_ii_select_too_many_index_match_ratio_env); + } + } + + return GRN_SUCCESS; +} + +grn_rc +grn_ii_fin(void) +{ + return GRN_SUCCESS; +} + /* segment */ inline static uint32_t @@ -4112,16 +4150,11 @@ exit : static inline void grn_ii_cursor_set_min(grn_ctx *ctx, grn_ii_cursor *c, grn_id min) { - char grn_ii_cursor_set_min_enable_env[GRN_ENV_BUFFER_SIZE]; - if (c->min >= min) { return; } - grn_getenv("GRN_II_CURSOR_SET_MIN_ENABLE", - grn_ii_cursor_set_min_enable_env, - GRN_ENV_BUFFER_SIZE); - if (grn_ii_cursor_set_min_enable_env[0]) { + if (grn_ii_cursor_set_min_enable) { c->min = min; if (c->buf && c->pc.rid < c->min && c->curr_chunk < c->nchunks) { uint32_t i, skip_chunk = 0; @@ -6227,16 +6260,6 @@ grn_ii_select_sequential_search(grn_ctx *ctx, grn_bool processed = GRN_TRUE; { - /* Disabled by default. */ - double too_many_index_match_ratio = -1; - char too_many_index_match_ratio_env[GRN_ENV_BUFFER_SIZE]; - grn_getenv("GRN_II_SELECT_TOO_MANY_INDEX_MATCH_RATIO", - too_many_index_match_ratio_env, - GRN_ENV_BUFFER_SIZE); - if (too_many_index_match_ratio_env[0]) { - too_many_index_match_ratio = atof(too_many_index_match_ratio_env); - } - if (!grn_ii_select_sequential_search_should_use(ctx, ii, raw_query, @@ -6247,7 +6270,7 @@ grn_ii_select_sequential_search(grn_ctx *ctx, optarg, token_infos, n_token_infos, - too_many_index_match_ratio)) { + grn_ii_select_too_many_index_match_ratio)) { return GRN_FALSE; } } -------------- next part -------------- HTML����������������������������...Download