Enable method cache by default.

Introduced `MRB_NO_METHOD_CACHE` which is inverse of `MRB_METHOD_CACHE`
that should be enabled intestinally. In addition, the default cache is
made bigger (128 -> 256).
parent fb5e8ab6
...@@ -163,12 +163,12 @@ largest value of required alignment. ...@@ -163,12 +163,12 @@ largest value of required alignment.
* Default value is `128`. * Default value is `128`.
* Specifies initial capacity of `RString` created by `mrb_str_buf_new` function.. * Specifies initial capacity of `RString` created by `mrb_str_buf_new` function..
`MRB_METHOD_CACHE` `MRB_NO_METHOD_CACHE`
* Improve performance for method dispatch. * Disable method cache to save memory.
`MRB_METHOD_CACHE_SIZE` `MRB_METHOD_CACHE_SIZE`
* Default value is `128`. * Default value is `256`.
* Ignored if `MRB_METHOD_CACHE` is not defined. * Ignored if `MRB_NO_METHOD_CACHE` is defined.
* Need to be the power of 2. * Need to be the power of 2.
`MRB_METHOD_T_STRUCT` `MRB_METHOD_T_STRUCT`
......
...@@ -31,10 +31,10 @@ ...@@ -31,10 +31,10 @@
/* exclude floating point numbers */ /* exclude floating point numbers */
//#define MRB_WITHOUT_FLOAT //#define MRB_WITHOUT_FLOAT
/* add -DMRB_METHOD_CACHE to use method cache to improve performance */ /* add -DMRB_NO_METHOD_CACHE to disable method cache to save memory */
//#define MRB_METHOD_CACHE //#define MRB_NO_METHOD_CACHE
/* size of the method cache (need to be the power of 2) */ /* size of the method cache (need to be the power of 2) */
//#define MRB_METHOD_CACHE_SIZE (1<<7) //#define MRB_METHOD_CACHE_SIZE (1<<8)
/* add -DMRB_METHOD_T_STRUCT on machines that use higher bits of pointers */ /* add -DMRB_METHOD_T_STRUCT on machines that use higher bits of pointers */
/* no MRB_METHOD_T_STRUCT requires highest 2 bits of function pointers to be zero */ /* no MRB_METHOD_T_STRUCT requires highest 2 bits of function pointers to be zero */
...@@ -160,6 +160,10 @@ ...@@ -160,6 +160,10 @@
/* A profile for micro controllers */ /* A profile for micro controllers */
#if defined(MRB_CONSTRAINED_BASELINE_PROFILE) #if defined(MRB_CONSTRAINED_BASELINE_PROFILE)
# ifndef MRB_NO_METHOD_CACHE
# define MRB_NO_METHOD_CACHE
# endif
# ifndef KHASH_DEFAULT_SIZE # ifndef KHASH_DEFAULT_SIZE
# define KHASH_DEFAULT_SIZE 16 # define KHASH_DEFAULT_SIZE 16
# endif # endif
...@@ -177,10 +181,6 @@ ...@@ -177,10 +181,6 @@
/* A profile for desktop computers or workstations; rich memory! */ /* A profile for desktop computers or workstations; rich memory! */
#elif defined(MRB_MAIN_PROFILE) #elif defined(MRB_MAIN_PROFILE)
# ifndef MRB_METHOD_CACHE
# define MRB_METHOD_CACHE
# endif
# ifndef MRB_METHOD_CACHE_SIZE # ifndef MRB_METHOD_CACHE_SIZE
# define MRB_METHOD_CACHE_SIZE (1<<10) # define MRB_METHOD_CACHE_SIZE (1<<10)
# endif # endif
...@@ -195,10 +195,6 @@ ...@@ -195,10 +195,6 @@
/* A profile for server; mruby vm is long life */ /* A profile for server; mruby vm is long life */
#elif defined(MRB_HIGH_PROFILE) #elif defined(MRB_HIGH_PROFILE)
# ifndef MRB_METHOD_CACHE
# define MRB_METHOD_CACHE
# endif
# ifndef MRB_METHOD_CACHE_SIZE # ifndef MRB_METHOD_CACHE_SIZE
# define MRB_METHOD_CACHE_SIZE (1<<12) # define MRB_METHOD_CACHE_SIZE (1<<12)
# endif # endif
......
...@@ -188,11 +188,11 @@ struct mrb_context { ...@@ -188,11 +188,11 @@ struct mrb_context {
}; };
#ifdef MRB_METHOD_CACHE_SIZE #ifdef MRB_METHOD_CACHE_SIZE
# define MRB_METHOD_CACHE # undef MRB_NO_METHOD_CACHE
#else #else
/* default method cache size: 128 */ /* default method cache size: 256 */
/* cache size needs to be power of 2 */ /* cache size needs to be power of 2 */
# define MRB_METHOD_CACHE_SIZE (1<<7) # define MRB_METHOD_CACHE_SIZE (1<<8)
#endif #endif
/** /**
...@@ -218,7 +218,7 @@ typedef struct { ...@@ -218,7 +218,7 @@ typedef struct {
} mrb_method_t; } mrb_method_t;
#endif #endif
#ifdef MRB_METHOD_CACHE #ifndef MRB_NO_METHOD_CACHE
struct mrb_cache_entry { struct mrb_cache_entry {
struct RClass *c, *c0; struct RClass *c, *c0;
mrb_sym mid; mrb_sym mid;
...@@ -264,7 +264,7 @@ typedef struct mrb_state { ...@@ -264,7 +264,7 @@ typedef struct mrb_state {
mrb_gc gc; mrb_gc gc;
#ifdef MRB_METHOD_CACHE #ifndef MRB_NO_METHOD_CACHE
struct mrb_cache_entry cache[MRB_METHOD_CACHE_SIZE]; struct mrb_cache_entry cache[MRB_METHOD_CACHE_SIZE];
#endif #endif
......
...@@ -92,7 +92,7 @@ void mrb_gc_mark_mt(mrb_state*, struct RClass*); ...@@ -92,7 +92,7 @@ void mrb_gc_mark_mt(mrb_state*, struct RClass*);
size_t mrb_gc_mark_mt_size(mrb_state*, struct RClass*); size_t mrb_gc_mark_mt_size(mrb_state*, struct RClass*);
void mrb_gc_free_mt(mrb_state*, struct RClass*); void mrb_gc_free_mt(mrb_state*, struct RClass*);
#ifdef MRB_METHOD_CACHE #ifndef MRB_NO_METHOD_CACHE
void mrb_mc_clear_by_class(mrb_state *mrb, struct RClass* c); void mrb_mc_clear_by_class(mrb_state *mrb, struct RClass* c);
#else #else
#define mrb_mc_clear_by_class(mrb,c) #define mrb_mc_clear_by_class(mrb,c)
......
...@@ -292,7 +292,7 @@ mrb_define_class(mrb_state *mrb, const char *name, struct RClass *super) ...@@ -292,7 +292,7 @@ mrb_define_class(mrb_state *mrb, const char *name, struct RClass *super)
} }
static mrb_value mrb_bob_init(mrb_state *mrb, mrb_value); static mrb_value mrb_bob_init(mrb_state *mrb, mrb_value);
#ifdef MRB_METHOD_CACHE #ifndef MRB_NO_METHOD_CACHE
static void mc_clear_all(mrb_state *mrb); static void mc_clear_all(mrb_state *mrb);
static void mc_clear_by_id(mrb_state *mrb, struct RClass*, mrb_sym); static void mc_clear_by_id(mrb_state *mrb, struct RClass*, mrb_sym);
#else #else
...@@ -1404,7 +1404,7 @@ mrb_define_module_function(mrb_state *mrb, struct RClass *c, const char *name, m ...@@ -1404,7 +1404,7 @@ mrb_define_module_function(mrb_state *mrb, struct RClass *c, const char *name, m
mrb_define_module_function_id(mrb, c, mrb_intern_cstr(mrb, name), func, aspec); mrb_define_module_function_id(mrb, c, mrb_intern_cstr(mrb, name), func, aspec);
} }
#ifdef MRB_METHOD_CACHE #ifndef MRB_NO_METHOD_CACHE
static void static void
mc_clear_all(mrb_state *mrb) mc_clear_all(mrb_state *mrb)
{ {
...@@ -1456,7 +1456,7 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid) ...@@ -1456,7 +1456,7 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
khiter_t k; khiter_t k;
mrb_method_t m; mrb_method_t m;
struct RClass *c = *cp; struct RClass *c = *cp;
#ifdef MRB_METHOD_CACHE #ifndef MRB_NO_METHOD_CACHE
struct RClass *oc = c; struct RClass *oc = c;
int h = kh_int_hash_func(mrb, ((intptr_t)oc) ^ mid) & (MRB_METHOD_CACHE_SIZE-1); int h = kh_int_hash_func(mrb, ((intptr_t)oc) ^ mid) & (MRB_METHOD_CACHE_SIZE-1);
struct mrb_cache_entry *mc = &mrb->cache[h]; struct mrb_cache_entry *mc = &mrb->cache[h];
...@@ -1476,7 +1476,7 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid) ...@@ -1476,7 +1476,7 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid)
m = kh_value(h, k); m = kh_value(h, k);
if (MRB_METHOD_UNDEF_P(m)) break; if (MRB_METHOD_UNDEF_P(m)) break;
*cp = c; *cp = c;
#ifdef MRB_METHOD_CACHE #ifndef MRB_NO_METHOD_CACHE
mc->c = oc; mc->c = oc;
mc->c0 = c; mc->c0 = c;
mc->mid = mid; mc->mid = mid;
......
...@@ -10,7 +10,7 @@ MRuby::Build.new('full-debug') do |conf| ...@@ -10,7 +10,7 @@ MRuby::Build.new('full-debug') do |conf|
# include all core GEMs # include all core GEMs
conf.gembox 'full-core' conf.gembox 'full-core'
conf.cc.defines += %w(MRB_GC_STRESS MRB_METHOD_CACHE MRB_ENABLE_DEBUG_HOOK) conf.cc.defines += %w(MRB_GC_STRESS MRB_ENABLE_DEBUG_HOOK)
setup_option(conf) setup_option(conf)
conf.enable_test conf.enable_test
......
...@@ -5,7 +5,6 @@ MRuby::Build.new do |conf| ...@@ -5,7 +5,6 @@ MRuby::Build.new do |conf|
# include the GEM box # include the GEM box
conf.gembox 'full-core' conf.gembox 'full-core'
conf.cc.defines = %w(MRB_METHOD_CACHE)
conf.cc.flags << '-pg' conf.cc.flags << '-pg'
conf.linker.flags << '-pg' conf.linker.flags << '-pg'
......
...@@ -5,7 +5,7 @@ MRuby::Build.new('full-debug') do |conf| ...@@ -5,7 +5,7 @@ MRuby::Build.new('full-debug') do |conf|
# include all core GEMs # include all core GEMs
conf.gembox 'full-core' conf.gembox 'full-core'
conf.cc.flags += %w(-Werror=declaration-after-statement) conf.cc.flags += %w(-Werror=declaration-after-statement)
conf.cc.defines += %w(MRB_GC_STRESS MRB_METHOD_CACHE MRB_ENABLE_DEBUG_HOOK) conf.cc.defines += %w(MRB_GC_STRESS MRB_ENABLE_DEBUG_HOOK)
conf.enable_test conf.enable_test
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment