summaryrefslogtreecommitdiffhomepage
path: root/include/mruby.h
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-08-22 22:17:01 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-08-22 22:17:01 +0900
commit4c9a60487799b923ff905def46cb2497bcc1e4dd (patch)
tree4a22849a01477b03c89dfdac904d777751799965 /include/mruby.h
parenta65f4dbb3237cf06c75b70af0ed4ee076d7fec31 (diff)
downloadmruby-4c9a60487799b923ff905def46cb2497bcc1e4dd.tar.gz
mruby-4c9a60487799b923ff905def46cb2497bcc1e4dd.zip
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.
Diffstat (limited to 'include/mruby.h')
-rw-r--r--include/mruby.h20
1 files changed, 20 insertions, 0 deletions
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 */