Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: src/objects.cc

Issue 1751643003: [esnext] use map instance_descriptors() when possible in Object.values/entries() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@ObjectValuesEntriesPerf
Patch Set: trial: generate enum cache when possible, too Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 8821 matching lines...) Expand 10 before | Expand all | Expand 10 after
8832 MaybeHandle<FixedArray>()); 8832 MaybeHandle<FixedArray>());
8833 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion); 8833 Handle<FixedArray> keys = accumulator.GetKeys(keys_conversion);
8834 DCHECK(ContainsOnlyValidKeys(keys)); 8834 DCHECK(ContainsOnlyValidKeys(keys));
8835 return keys; 8835 return keys;
8836 } 8836 }
8837 8837
8838 MaybeHandle<FixedArray> GetOwnValuesOrEntries(Isolate* isolate, 8838 MaybeHandle<FixedArray> GetOwnValuesOrEntries(Isolate* isolate,
8839 Handle<JSReceiver> object, 8839 Handle<JSReceiver> object,
8840 PropertyFilter filter, 8840 PropertyFilter filter,
8841 bool get_entries) { 8841 bool get_entries) {
8842 PropertyFilter key_filter = 8842 Handle<FixedArray> keys;
8843 static_cast<PropertyFilter>(filter & ~ONLY_ENUMERABLE); 8843 bool use_enum_cache = false;
8844 KeyAccumulator accumulator(isolate, OWN_ONLY, key_filter); 8844 bool maybe_enum_cache = filter == ENUMERABLE_STRINGS &&
8845 MAYBE_RETURN(GetKeys_Internal(isolate, object, object, OWN_ONLY, key_filter, 8845 object->IsJSObject() &&
Camillo Bruni 2016/03/02 09:21:51 You could probably include the OnlyHasSimpleProper
8846 &accumulator), 8846 JSObject::cast(*object)->elements() ==
8847 MaybeHandle<FixedArray>()); 8847 isolate->heap()->empty_fixed_array();
8848 Handle<FixedArray> keys = accumulator.GetKeys(CONVERT_TO_STRING); 8848 int enum_length = object->map()->EnumLength();
8849 DCHECK(ContainsOnlyValidKeys(keys)); 8849
8850 if (maybe_enum_cache && enum_length != kInvalidEnumCacheSentinel) {
8851 DCHECK(!object->IsJSProxy());
8852 if (enum_length == 0) {
8853 return isolate->factory()->empty_fixed_array();
8854 }
8855 Handle<FixedArray> cache(
8856 object->map()->instance_descriptors()->GetEnumCache());
8857 keys = isolate->factory()->CopyFixedArrayUpTo(cache, enum_length);
8858 use_enum_cache = true;
8859 } else if (maybe_enum_cache && object->HasFastProperties()) {
Camillo Bruni 2016/03/02 09:21:51 With the above OnlyHasSimpleProperties check the H
8860 keys = GetFastEnumPropertyKeys(isolate, Handle<JSObject>::cast(object));
8861 use_enum_cache = true;
8862 } else {
8863 PropertyFilter key_filter =
8864 static_cast<PropertyFilter>(filter & ~ONLY_ENUMERABLE);
8865 KeyAccumulator accumulator(isolate, OWN_ONLY, key_filter);
8866 MAYBE_RETURN(GetKeys_Internal(isolate, object, object, OWN_ONLY, key_filter,
8867 &accumulator),
8868 MaybeHandle<FixedArray>());
8869 keys = accumulator.GetKeys(CONVERT_TO_STRING);
8870 DCHECK(ContainsOnlyValidKeys(keys));
8871 }
8850 8872
8851 Handle<FixedArray> values_or_entries = 8873 Handle<FixedArray> values_or_entries =
8852 isolate->factory()->NewFixedArray(keys->length()); 8874 isolate->factory()->NewFixedArray(keys->length());
8853 int length = 0; 8875 int length = 0;
8854 8876
8855 for (int i = 0; i < keys->length(); ++i) { 8877 for (int i = 0; i < keys->length(); ++i) {
8856 Handle<Name> key = Handle<Name>::cast(handle(keys->get(i), isolate)); 8878 Handle<Name> key = Handle<Name>::cast(handle(keys->get(i), isolate));
8857 8879
8858 if (filter & ONLY_ENUMERABLE) { 8880 if ((filter & ONLY_ENUMERABLE) && !use_enum_cache) {
8859 PropertyDescriptor descriptor; 8881 PropertyDescriptor descriptor;
8860 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( 8882 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor(
8861 isolate, object, key, &descriptor); 8883 isolate, object, key, &descriptor);
8862 MAYBE_RETURN(did_get_descriptor, MaybeHandle<FixedArray>()); 8884 MAYBE_RETURN(did_get_descriptor, MaybeHandle<FixedArray>());
8863 if (!did_get_descriptor.FromJust() || !descriptor.enumerable()) continue; 8885 if (!did_get_descriptor.FromJust() || !descriptor.enumerable()) continue;
8864 } 8886 }
8865 8887
8866 Handle<Object> value; 8888 Handle<Object> value;
8867 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 8889 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
8868 isolate, value, JSReceiver::GetPropertyOrElement(object, key), 8890 isolate, value, JSReceiver::GetPropertyOrElement(object, key),
8869 MaybeHandle<FixedArray>()); 8891 MaybeHandle<FixedArray>());
8870 8892
8893 if (use_enum_cache &&
8894 object->map()->EnumLength() == kInvalidEnumCacheSentinel) {
Camillo Bruni 2016/03/02 09:21:51 How about just doing a map check (see FastAssign i
caitp (gmail) 2016/03/02 11:53:21 my reasoning for this method is that, accessors ca
Camillo Bruni 2016/03/02 17:50:07 IMO that would be partially correct. But it could
caitp (gmail) 2016/03/02 18:17:28 Maybe I'll do that in a follow-up just so I can se
8895 // A property descriptor was replaced, enumerable status may have changed
8896 use_enum_cache = false;
8897 }
8898
8871 if (get_entries) { 8899 if (get_entries) {
8872 Handle<FixedArray> entry_storage = 8900 Handle<FixedArray> entry_storage =
8873 isolate->factory()->NewUninitializedFixedArray(2); 8901 isolate->factory()->NewUninitializedFixedArray(2);
8874 entry_storage->set(0, *key); 8902 entry_storage->set(0, *key);
8875 entry_storage->set(1, *value); 8903 entry_storage->set(1, *value);
8876 value = isolate->factory()->NewJSArrayWithElements(entry_storage, 8904 value = isolate->factory()->NewJSArrayWithElements(entry_storage,
8877 FAST_ELEMENTS, 2); 8905 FAST_ELEMENTS, 2);
8878 } 8906 }
8879 8907
8880 values_or_entries->set(length, *value); 8908 values_or_entries->set(length, *value);
(...skipping 10943 matching lines...) Expand 10 before | Expand all | Expand 10 after
19824 if (cell->value() != *new_value) { 19852 if (cell->value() != *new_value) {
19825 cell->set_value(*new_value); 19853 cell->set_value(*new_value);
19826 Isolate* isolate = cell->GetIsolate(); 19854 Isolate* isolate = cell->GetIsolate();
19827 cell->dependent_code()->DeoptimizeDependentCodeGroup( 19855 cell->dependent_code()->DeoptimizeDependentCodeGroup(
19828 isolate, DependentCode::kPropertyCellChangedGroup); 19856 isolate, DependentCode::kPropertyCellChangedGroup);
19829 } 19857 }
19830 } 19858 }
19831 19859
19832 } // namespace internal 19860 } // namespace internal
19833 } // namespace v8 19861 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698