Report abuse


			
diff --git a/shotgun/lib/cpu_instructions.c b/shotgun/lib/cpu_instructions.c
index 0680f62..a1b7f8e 100644
--- a/shotgun/lib/cpu_instructions.c
+++ b/shotgun/lib/cpu_instructions.c
@@ -337,7 +337,18 @@ static inline OBJECT cpu_locate_method(STATE, cpu c, OBJECT klass, OBJECT obj, O

 OBJECT cpu_compile_method(STATE, OBJECT cm) {
   OBJECT ba;
-  ba = bytearray_dup(state, cmethod_get_bytecodes(cm));
+  ba = cmethod_get_compiled(cm);
+  if(NIL_P(ba)) {
+    /* First time this method has been compiled */
+    ba = bytearray_dup(state, cmethod_get_bytecodes(cm));
+  }
+  else {
+    /* Method is being recompiled due to a change to the iseq.
+       Reuse the existing compiled bytearray so that we don't
+       need to reload all contexts that have a reference to this
+       compiled method. */
+    object_copy_body(state, cmethod_get_bytecodes(cm), ba);
+  }

   /* If this is not a big endian platform, we need to adjust
      the iseq to have the right order */