From 4c9a60487799b923ff905def46cb2497bcc1e4dd Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 22 Aug 2017 22:17:01 +0900 Subject: Added method cache. To enable method cache, define `MRB_METHOD_CACHE` or `MRB_METHOD_CACHE_SIZE`. The cache size must be power of 2. The default cache size is 128. The measurement: I measured simple benchmarks found in benchmark/ directory. With method cache enabled, we gained 6-8% performance improvement, with 97-99% cache hit rate. --- include/mruby.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'include/mruby.h') diff --git a/include/mruby.h b/include/mruby.h index 556dc41e8..cd9fca7f4 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -157,6 +157,22 @@ struct mrb_context { struct RFiber *fib; }; +#ifdef MRB_METHOD_CACHE_SIZE +# define MRB_METHOD_CACHE +#else +/* default method cache size: 128 */ +/* cache size needs to be power of 2 */ +# define MRB_METHOD_CACHE_SIZE (1<<7) +#endif + +#ifdef MRB_METHOD_CACHE +struct mrb_cache_entry { + struct RClass *c; + mrb_sym mid; + struct RProc *m; +}; +#endif + struct mrb_jmpbuf; typedef void (*mrb_atexit_func)(struct mrb_state*); @@ -197,6 +213,10 @@ typedef struct mrb_state { struct alloca_header *mems; mrb_gc gc; +#ifdef MRB_METHOD_CACHE + struct mrb_cache_entry cache[MRB_METHOD_CACHE_SIZE]; +#endif + mrb_sym symidx; struct kh_n2s *name2sym; /* symbol hash */ struct symbol_name *symtbl; /* symbol table */ -- cgit v1.2.3