Revision: 2681
Author: [email protected]
Date: Thu Aug 13 05:35:59 2009
Log: Avoid map transitions and multiple backing arrays for builtin  
prototypes
while adding functions and other properties.  This gives around 2% on
context-create, more if we don't GC on every new context.  Also fix
accounting bug in cell space.
Review URL: http://codereview.chromium.org/165449
http://code.google.com/p/v8/source/detail?r=2681

Modified:
  /branches/bleeding_edge/src/heap.cc
  /branches/bleeding_edge/src/math.js
  /branches/bleeding_edge/src/runtime.cc
  /branches/bleeding_edge/src/runtime.h
  /branches/bleeding_edge/src/spaces.h
  /branches/bleeding_edge/src/v8natives.js

=======================================
--- /branches/bleeding_edge/src/heap.cc Thu Aug 13 05:03:42 2009
+++ /branches/bleeding_edge/src/heap.cc Thu Aug 13 05:35:59 2009
@@ -277,7 +277,9 @@
  int Heap::SizeOfObjects() {
    int total = 0;
    AllSpaces spaces;
-  while (Space* space = spaces.next()) total += space->Size();
+  while (Space* space = spaces.next()) {
+    total += space->Size();
+  }
    return total;
  }

=======================================
--- /branches/bleeding_edge/src/math.js Tue Jul  7 01:55:55 2009
+++ /branches/bleeding_edge/src/math.js Thu Aug 13 05:35:59 2009
@@ -184,6 +184,7 @@
  function SetupMath() {
    // Setup math constants.
    // ECMA-262, section 15.8.1.1.
+  %OptimizeObjectForAddingMultipleProperties($Math, 26);
    %SetProperty($Math,
                 "E",
                 2.7182818284590452354,
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Thu Aug 13 03:25:35 2009
+++ /branches/bleeding_edge/src/runtime.cc      Thu Aug 13 05:35:59 2009
@@ -1020,6 +1020,30 @@

    return *value;
  }
+
+
+static Object* Runtime_OptimizeObjectForAddingMultipleProperties(
+    Arguments args) {
+  HandleScope scope;
+  ASSERT(args.length() == 2);
+  CONVERT_ARG_CHECKED(JSObject, object, 0);
+  CONVERT_SMI_CHECKED(properties, args[1]);
+  if (object->HasFastProperties()) {
+    NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties);
+  }
+  return *object;
+}
+
+
+static Object* Runtime_TransformToFastProperties(Arguments args) {
+  HandleScope scope;
+  ASSERT(args.length() == 1);
+  CONVERT_ARG_CHECKED(JSObject, object, 0);
+  if (!object->HasFastProperties() && !object->IsGlobalObject()) {
+    TransformToFastProperties(object, 0);
+  }
+  return *object;
+}


  static Object* Runtime_RegExpExec(Arguments args) {
=======================================
--- /branches/bleeding_edge/src/runtime.h       Thu Jul  2 05:26:31 2009
+++ /branches/bleeding_edge/src/runtime.h       Thu Aug 13 05:35:59 2009
@@ -247,6 +247,8 @@
    F(InitializeVarGlobal, -1 /* 1 or 2 */) \
    F(InitializeConstGlobal, 2) \
    F(InitializeConstContextSlot, 3) \
+  F(OptimizeObjectForAddingMultipleProperties, 2) \
+  F(TransformToFastProperties, 1) \
    \
    /* Debugging */ \
    F(DebugPrint, 1) \
=======================================
--- /branches/bleeding_edge/src/spaces.h        Thu Aug 13 05:03:42 2009
+++ /branches/bleeding_edge/src/spaces.h        Thu Aug 13 05:35:59 2009
@@ -1574,7 +1574,7 @@
    // Give a fixed sized block of memory to the space's free list.
    void Free(Address start) {
      free_list_.Free(start);
-    accounting_stats_.DeallocateBytes(Map::kSize);
+    accounting_stats_.DeallocateBytes(object_size_in_bytes_);
    }

    // Prepares for a mark-compact GC.
=======================================
--- /branches/bleeding_edge/src/v8natives.js    Mon Jun 29 03:45:16 2009
+++ /branches/bleeding_edge/src/v8natives.js    Thu Aug 13 05:35:59 2009
@@ -46,12 +46,16 @@

  // Helper function used to install functions on objects.
  function InstallFunctions(object, attributes, functions) {
+  if (functions.length >= 8) {
+    %OptimizeObjectForAddingMultipleProperties(object, functions.length >>  
1);
+  }
    for (var i = 0; i < functions.length; i += 2) {
      var key = functions[i];
      var f = functions[i + 1];
      %FunctionSetName(f, key);
      %SetProperty(object, key, f, attributes);
    }
+  %TransformToFastProperties(object);
  }

  // Emulates JSC by installing functions on a hidden prototype that
@@ -454,8 +458,10 @@

  function SetupNumber() {
    // Setup the constructor property on the Number prototype object.
+  %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8);
    %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM);

+  %OptimizeObjectForAddingMultipleProperties($Number, 5);
    // ECMA-262 section 15.7.3.1.
    %SetProperty($Number,
                 "MAX_VALUE",

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to