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

ruby-changes:40308

From: ko1 <ko1@a...>
Date: Fri, 30 Oct 2015 18:33:26 +0900 (JST)
Subject: [ruby-changes:40308] ko1:r52389 (trunk): * gc.c (newobj_slowpath): reduce 1 parameter to use only registers

ko1	2015-10-30 18:33:08 +0900 (Fri, 30 Oct 2015)

  New Revision: 52389

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

  Log:
    * gc.c (newobj_slowpath): reduce 1 parameter to use only registers
      for performance.
    
      On my laptop, 'N.times{x = []}' (where N = 29_000_000) is
      1.86 sec -> 1.74 sec.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52388)
+++ ChangeLog	(revision 52389)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Oct 30 18:09:51 2015  Koichi Sasada  <ko1@a...>
+
+	* gc.c (newobj_slowpath): reduce 1 parameter to use only registers
+	  for performance.
+
+	  On my laptop, 'N.times{x = []}' (where N = 29_000_000) is
+	  1.86 sec -> 1.74 sec.
+
 Fri Oct 30 12:53:21 2015  yui-knk  <spiketeika@g...>
 
 	* test/ruby/test_call.rb: added test for safe navigation operator.
Index: gc.c
===================================================================
--- gc.c	(revision 52388)
+++ gc.c	(revision 52389)
@@ -1787,10 +1787,8 @@ newobj_init(VALUE klass, VALUE flags, VA https://github.com/ruby/ruby/blob/trunk/gc.c#L1787
     return obj;
 }
 
-NOINLINE(static VALUE newobj_slowpath(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, int wb_protected, rb_objspace_t *objspace));
-
-static VALUE
-newobj_slowpath(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, int wb_protected, rb_objspace_t *objspace)
+static inline VALUE
+newobj_slowpath(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, rb_objspace_t *objspace, int wb_protected)
 {
     VALUE obj;
 
@@ -1809,11 +1807,26 @@ newobj_slowpath(VALUE klass, VALUE flags https://github.com/ruby/ruby/blob/trunk/gc.c#L1807
     }
 
     obj = heap_get_freeobj(objspace, heap_eden);
-    newobj_init(klass, flags, v1, v2, v3, wb_protected, objspace, obj);
+    newobj_init(klass, (flags & ~FL_WB_PROTECTED), v1, v2, v3, (flags & FL_WB_PROTECTED) ? TRUE : FALSE, objspace, obj);
     gc_event_hook(objspace, RUBY_INTERNAL_EVENT_NEWOBJ, obj);
     return obj;
 }
 
+NOINLINE(static VALUE newobj_slowpath_wb_protected(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, rb_objspace_t *objspace));
+NOINLINE(static VALUE newobj_slowpath_wb_unprotected(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, rb_objspace_t *objspace));
+
+static VALUE
+newobj_slowpath_wb_protected(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, rb_objspace_t *objspace)
+{
+    return newobj_slowpath(klass, flags, v1, v2, v3, objspace, TRUE);
+}
+
+static VALUE
+newobj_slowpath_wb_unprotected(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, rb_objspace_t *objspace)
+{
+    return newobj_slowpath(klass, flags, v1, v2, v3, objspace, FALSE);
+}
+
 static inline VALUE
 newobj_of(VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, int wb_protected)
 {
@@ -1829,24 +1842,20 @@ newobj_of(VALUE klass, VALUE flags, VALU https://github.com/ruby/ruby/blob/trunk/gc.c#L1842
 	}
     }
 #endif
-    if (LIKELY(!(during_gc ||
-		 ruby_gc_stressful ||
-		 gc_event_hook_available_p(objspace)) &&
-	       (obj = heap_get_freeobj_head(objspace, heap_eden)) != Qfalse)) {
+    if (!(during_gc ||
+	  ruby_gc_stressful ||
+	  gc_event_hook_available_p(objspace)) &&
+	(obj = heap_get_freeobj_head(objspace, heap_eden)) != Qfalse) {
 	return newobj_init(klass, flags, v1, v2, v3, wb_protected, objspace, obj);
     }
     else {
-	return newobj_slowpath(klass, flags, v1, v2, v3, wb_protected, objspace);
+	return wb_protected ?
+	  newobj_slowpath_wb_protected(klass, flags, v1, v2, v3, objspace) :
+	  newobj_slowpath_wb_unprotected(klass, flags, v1, v2, v3, objspace);
     }
 }
 
 VALUE
-rb_newobj(void)
-{
-    return newobj_of(0, T_NONE, 0, 0, 0, FALSE);
-}
-
-VALUE
 rb_wb_unprotected_newobj_of(VALUE klass, VALUE flags)
 {
     if (RGENGC_CHECK_MODE > 0) assert((flags & FL_WB_PROTECTED) == 0);
@@ -1860,6 +1869,14 @@ rb_wb_protected_newobj_of(VALUE klass, V https://github.com/ruby/ruby/blob/trunk/gc.c#L1869
     return newobj_of(klass, flags, 0, 0, 0, TRUE);
 }
 
+/* for compatibility */
+
+VALUE
+rb_newobj(void)
+{
+    return newobj_of(0, T_NONE, 0, 0, 0, FALSE);
+}
+
 VALUE
 rb_newobj_of(VALUE klass, VALUE flags)
 {

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

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