Reviewers: Kevin Millikin, Mads Ager,

Message:
This is a proposal to speed up calls to functions defined as object literal
properties.

Description:
Optimize calls to object literal properties that are initialized with a function
literal.

Instead of eagerly adding those properties as normal properties to the
boilerplate
object we skip them during creation of the object literal and add them as
constant
functions when assigning values to computed properties afterwards.

This allows fast calls and inlining of functions like:

var o = {f: function() { return "foo"; }}
o.f();



Please review this at http://codereview.chromium.org/6240012/

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/parser.cc
  M     src/runtime.cc


Index: src/parser.cc
===================================================================
--- src/parser.cc       (revision 6508)
+++ src/parser.cc       (working copy)
@@ -3184,6 +3184,15 @@
     Handle<Object> value = GetBoilerplateValue(property->value());
     is_simple_acc = is_simple_acc && !value->IsUndefined();

+    // Add the hole value for function literals. Those properties will not
+    // be added to the boilerplate. Instead the StoreIC will add them as
+    // constant functions when assigning values for computed properties.
+    if (property->value()->AsFunctionLiteral() != NULL &&
+        property->kind() != ObjectLiteral::Property::GETTER &&
+        property->kind() != ObjectLiteral::Property::SETTER) {
+      value = Factory::the_hole_value();
+    }
+
     // Keep track of the number of elements in the object literal and
     // the largest element index.  If the largest element index is
     // much larger than the number of elements, creating an object
Index: src/runtime.cc
===================================================================
--- src/runtime.cc      (revision 6508)
+++ src/runtime.cc      (working copy)
@@ -243,11 +243,13 @@
     int number_of_symbol_keys = 0;
     for (int p = 0; p != properties_length; p += 2) {
       Object* key = constant_properties->get(p);
+      Object* value = constant_properties->get(p + 1);
       uint32_t element_index = 0;
       if (key->IsSymbol()) {
         number_of_symbol_keys++;
-      } else if (key->ToArrayIndex(&element_index)) {
- // An index key does not require space in the property backing store.
+      } else if (key->ToArrayIndex(&element_index) || value->IsTheHole()) {
+        // An index key or a function literal (marked with the hole value)
+        // does not require space in the property backing store.
         number_of_properties--;
       } else {
         // Bail out as a non-symbol non-index key makes caching impossible.
@@ -320,6 +322,11 @@
     for (int index = 0; index < length; index +=2) {
       Handle<Object> key(constant_properties->get(index+0));
       Handle<Object> value(constant_properties->get(index+1));
+
+      // Skip properties initialized with a function literal. They are
+      // marked with the hole value.
+      if (value->IsTheHole()) continue;
+
       if (value->IsFixedArray()) {
         // The value contains the constant_properties of a
         // simple object literal.


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

Reply via email to