[前][次][番号順一覧][スレッド一覧]

ruby-changes:31176

From: ko1 <ko1@a...>
Date: Fri, 11 Oct 2013 20:45:47 +0900 (JST)
Subject: [ruby-changes:31176] ko1:r43255 (trunk): * gc.c, parse.y: support generational Symbol relatetd marking.

ko1	2013-10-11 20:45:38 +0900 (Fri, 11 Oct 2013)

  New Revision: 43255

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43255

  Log:
    * gc.c, parse.y: support generational Symbol relatetd marking.
      Each symbols has String objects respectively to represent
      Symbols.
      These objects are marked only when:
    * full marking
    * new symbols are added
      This hack reduce symbols (related strings) marking time.
      For example, on my Linux environment, the following code
      "20_000_000.times{''}"
      with 40k symbols (similar symbol number on Rails 3.2.14 app,
      @jugyo tells me) boosts, from 7.3sec to 4.2sec.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
    trunk/internal.h
    trunk/parse.y
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43254)
+++ ChangeLog	(revision 43255)
@@ -1,3 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct 11 20:35:59 2013  Koichi Sasada  <ko1@a...>
+
+	* gc.c, parse.y: support generational Symbol relatetd marking.
+	  Each symbols has String objects respectively to represent
+	  Symbols.
+	  These objects are marked only when:
+	  * full marking
+	  * new symbols are added
+	  This hack reduce symbols (related strings) marking time.
+	  For example, on my Linux environment, the following code
+	    "20_000_000.times{''}"
+	  with 40k symbols (similar symbol number on Rails 3.2.14 app,
+	  @jugyo tells me) boosts, from 7.3sec to 4.2sec.
+
+`	* internal.h: change prototype of rb_gc_mark_symbols().
+
 Fri Oct 11 19:27:22 2013  Akinori MUSHA  <knu@i...>
 
 	* misc/ruby-electric.el: Import ruby-electric.el 2.0.1 which fixes
Index: gc.c
===================================================================
--- gc.c	(revision 43254)
+++ gc.c	(revision 43255)
@@ -3580,7 +3580,7 @@ gc_marks_body(rb_objspace_t *objspace, i https://github.com/ruby/ruby/blob/trunk/gc.c#L3580
     mark_current_machine_context(objspace, th);
 
     MARK_CHECKPOINT;
-    rb_gc_mark_symbols();
+    rb_gc_mark_symbols(minor_gc == 0);
 
     MARK_CHECKPOINT;
     rb_gc_mark_encodings();
Index: parse.y
===================================================================
--- parse.y	(revision 43254)
+++ parse.y	(revision 43255)
@@ -10183,6 +10183,7 @@ static struct symbols { https://github.com/ruby/ruby/blob/trunk/parse.y#L10183
     st_table *id_ivar2;
 #endif
     VALUE op_sym[tLAST_OP_ID];
+    int minor_marked;
 } global_symbols = {tLAST_TOKEN};
 
 static const struct st_hash_type symhash = {
@@ -10237,11 +10238,14 @@ Init_sym(void) https://github.com/ruby/ruby/blob/trunk/parse.y#L10238
 }
 
 void
-rb_gc_mark_symbols(void)
+rb_gc_mark_symbols(int full_marking)
 {
-    rb_mark_tbl(global_symbols.id_str);
-    rb_gc_mark_locations(global_symbols.op_sym,
-			 global_symbols.op_sym + numberof(global_symbols.op_sym));
+    if (full_marking || global_symbols.minor_marked == 0) {
+	rb_mark_tbl(global_symbols.id_str);
+	rb_gc_mark_locations(global_symbols.op_sym,
+			     global_symbols.op_sym + numberof(global_symbols.op_sym));
+	global_symbols.minor_marked = 1;
+    }
 }
 #endif /* !RIPPER */
 
@@ -10425,6 +10429,7 @@ register_symid_str(ID id, VALUE str) https://github.com/ruby/ruby/blob/trunk/parse.y#L10429
 
     st_add_direct(global_symbols.sym_id, (st_data_t)str, id);
     st_add_direct(global_symbols.id_str, id, (st_data_t)str);
+    global_symbols.minor_marked = 0;
     return id;
 }
 
@@ -10628,6 +10633,7 @@ rb_id2str(ID id) https://github.com/ruby/ruby/blob/trunk/parse.y#L10633
 		str = rb_usascii_str_new(name, 1);
 		OBJ_FREEZE(str);
 		global_symbols.op_sym[i] = str;
+		global_symbols.minor_marked = 0;
 	    }
 	    return str;
 	}
@@ -10638,6 +10644,7 @@ rb_id2str(ID id) https://github.com/ruby/ruby/blob/trunk/parse.y#L10644
 		    str = rb_usascii_str_new2(op_tbl[i].name);
 		    OBJ_FREEZE(str);
 		    global_symbols.op_sym[i] = str;
+		    global_symbols.minor_marked = 0;
 		}
 		return str;
 	    }
Index: internal.h
===================================================================
--- internal.h	(revision 43254)
+++ internal.h	(revision 43255)
@@ -578,7 +578,7 @@ int rb_is_local_name(VALUE name); https://github.com/ruby/ruby/blob/trunk/internal.h#L578
 int rb_is_method_name(VALUE name);
 int rb_is_junk_name(VALUE name);
 void rb_gc_mark_parser(void);
-void rb_gc_mark_symbols(void);
+void rb_gc_mark_symbols(int full_marking);
 
 /* proc.c */
 VALUE rb_proc_location(VALUE self);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]