Storing the frame on the map means we don't need the array
diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c
index 1427f4b..edbbe6a 100644
--- a/ruby/ext/google/protobuf_c/encode_decode.c
+++ b/ruby/ext/google/protobuf_c/encode_decode.c
@@ -288,7 +288,7 @@
   native_slot_init(handlerdata->key_field_type, &frame->key_storage);
   native_slot_init(handlerdata->value_field_type, &frame->value_storage);
 
-  Map_push_frame(map,
+  Map_set_frame(map,
               TypedData_Wrap_Struct(rb_cObject, &MapParseFrame_type, frame));
 
   return frame;
@@ -327,7 +327,7 @@
       &frame->value_storage);
 
   Map_index_set(frame->map, key, value);
-  Map_pop_frame(frame->map);
+  Map_set_frame(frame->map, Qnil);
 
   return true;
 }
diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c
index 0787f6d..26e22dc 100644
--- a/ruby/ext/google/protobuf_c/map.c
+++ b/ruby/ext/google/protobuf_c/map.c
@@ -146,7 +146,7 @@
   Map* self = _self;
 
   rb_gc_mark(self->value_type_class);
-  rb_gc_mark(self->parse_frames);
+  rb_gc_mark(self->parse_frame);
 
   if (self->value_type == UPB_TYPE_STRING ||
       self->value_type == UPB_TYPE_BYTES ||
@@ -175,14 +175,10 @@
   return TypedData_Wrap_Struct(klass, &Map_type, self);
 }
 
-VALUE Map_push_frame(VALUE map, VALUE val) {
+VALUE Map_set_frame(VALUE map, VALUE val) {
   Map* self = ruby_to_Map(map);
-  return rb_ary_push(self->parse_frames, val);
-}
-
-VALUE Map_pop_frame(VALUE map) {
-  Map* self = ruby_to_Map(map);
-  return rb_ary_pop(self->parse_frames);
+  self->parse_frame = val;
+  return val;
 }
 
 static bool needs_typeclass(upb_fieldtype_t type) {
@@ -238,7 +234,7 @@
 
   self->key_type = ruby_to_fieldtype(argv[0]);
   self->value_type = ruby_to_fieldtype(argv[1]);
-  self->parse_frames = rb_ary_new();
+  self->parse_frame = Qnil;
 
   // Check that the key type is an allowed type.
   switch (self->key_type) {
diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h
index 8fd1bc6..f4b110f 100644
--- a/ruby/ext/google/protobuf_c/protobuf.h
+++ b/ruby/ext/google/protobuf_c/protobuf.h
@@ -395,7 +395,7 @@
   upb_fieldtype_t key_type;
   upb_fieldtype_t value_type;
   VALUE value_type_class;
-  VALUE parse_frames;
+  VALUE parse_frame;
   upb_strtable table;
 } Map;
 
@@ -404,8 +404,7 @@
 VALUE Map_alloc(VALUE klass);
 VALUE Map_init(int argc, VALUE* argv, VALUE self);
 void Map_register(VALUE module);
-VALUE Map_push_frame(VALUE self, VALUE val);
-VALUE Map_pop_frame(VALUE self);
+VALUE Map_set_frame(VALUE self, VALUE val);
 
 extern const rb_data_type_t Map_type;
 extern VALUE cMap;