Changeset 29943 in webkit for trunk/JavaScriptCore
- Timestamp:
- Feb 2, 2008, 4:20:34 PM (17 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r29941 r29943 1 2008-02-02 Darin Adler <[email protected]> 2 3 Reviewed by Geoff Garen. 4 5 PLT speedup related to <rdar://problem/5659272> REGRESSION: PLT .4% 6 slower due to r28884 (global variable symbol table optimization) 7 8 Geoff's theory is that the slowdown was due to copying hash tables when 9 putting things into the back/forward cache. If that's true, then this 10 should fix the problem. 11 12 (According to Geoff's measurements, in a PLT that exaggerates the 13 importance of symbol table saving during cached page creation, this 14 patch is a ~3X speedup in cached page creation, and a 9% speedup overall.) 15 16 * JavaScriptCore.exp: Updated. 17 18 * kjs/JSVariableObject.cpp: 19 (KJS::JSVariableObject::saveLocalStorage): Updated for changes to SavedProperty, 20 which has been revised to avoid initializing each SavedProperty twice when building 21 the array. Store the property names too, so we don't have to store the symbol table 22 separately. Do this by iterating the symbol table instead of the local storage vector. 23 (KJS::JSVariableObject::restoreLocalStorage): Ditto. Restore the symbol table as 24 well as the local storage vector. 25 26 * kjs/JSVariableObject.h: Removed save/restoreSymbolTable and do that work inside 27 save/restoreLocalStorage instead. Made restoreLocalStorage a non-const member function 28 that takes a const reference to a SavedProperties object. 29 30 * kjs/LocalStorage.h: Changed attributes to be unsigned instead of int to match 31 other declarations of attributes elsewhere. 32 33 * kjs/property_map.cpp: 34 (KJS::SavedProperties::SavedProperties): Updated for data member name change. 35 (KJS::PropertyMap::save): Updated for data member name change and to use the new 36 inline init function instead of setting the fields directly. This allows us to 37 skip initializing the SavedProperty objects when first allocating the array, and 38 just do it when we're actually setting up the individual elements. 39 (KJS::PropertyMap::restore): Updated for SavedProperty changes. 40 41 * kjs/property_map.h: Changed SavedProperty from a struct to a class. Set it up so 42 it does not get initialized at construction time to avoid initializing twice when 43 creating an array of SavedProperty. Removed the m_ prefixes from the members of 44 the SavedProperties struct. Generally we use m_ for class members and not struct. 45 1 46 2008-02-02 Tony Chang <[email protected]> 2 47 -
trunk/JavaScriptCore/JavaScriptCore.exp
r29810 r29943 157 157 __ZN3KJS16JSVariableObject14deletePropertyEPNS_9ExecStateERKNS_10IdentifierE 158 158 __ZN3KJS16JSVariableObject16getPropertyNamesEPNS_9ExecStateERNS_17PropertyNameArrayE 159 __ZN3KJS16JSVariableObject19restoreLocalStorageERKNS_15SavedPropertiesE 159 160 __ZN3KJS16ParserRefCounted3refEv 160 161 __ZN3KJS16ParserRefCounted5derefEv … … 246 247 __ZNK3KJS13ArrayInstance7getItemEj 247 248 __ZNK3KJS14JSGlobalObject12saveBuiltinsERNS_13SavedBuiltinsE 248 __ZNK3KJS16JSVariableObject15saveSymbolTableERN3WTF7HashMapINS1_6RefPtrINS_7UString3RepEEEmNS_17IdentifierRepHashENS_23IdentifierRepHashTraitsENS_26SymbolTableIndexHashTraitsEEE249 249 __ZNK3KJS16JSVariableObject16saveLocalStorageERNS_15SavedPropertiesE 250 __ZNK3KJS16JSVariableObject18restoreSymbolTableERN3WTF7HashMapINS1_6RefPtrINS_7UString3RepEEEmNS_17IdentifierRepHashENS_23IdentifierRepHashTraitsENS_26SymbolTableIndexHashTraitsEEE251 __ZNK3KJS16JSVariableObject19restoreLocalStorageERNS_15SavedPropertiesE252 250 __ZNK3KJS19InternalFunctionImp14implementsCallEv 253 251 __ZNK3KJS19InternalFunctionImp21implementsHasInstanceEv -
trunk/JavaScriptCore/kjs/JSVariableObject.cpp
r29663 r29943 1 1 /* 2 * Copyright (C) 2007 Apple Inc.All rights reserved.2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 37 37 UString::Rep* IdentifierRepHashTraits::nullRepPtr = &UString::Rep::null; // Didn't want to make a whole source file for just this. 38 38 39 void JSVariableObject::saveSymbolTable(SymbolTable& s) const40 {41 s = *d->symbolTable;42 }43 44 void JSVariableObject::restoreSymbolTable(SymbolTable& s) const45 {46 *d->symbolTable = s;47 }48 49 39 void JSVariableObject::saveLocalStorage(SavedProperties& p) const 50 40 { 51 unsigned count = d->localStorage.size(); 41 ASSERT(d->symbolTable); 42 ASSERT(static_cast<size_t>(d->symbolTable->size()) == d->localStorage.size()); 52 43 53 p.m_properties.clear(); 54 p.m_count = count; 44 unsigned count = d->symbolTable->size(); 45 46 p.properties.clear(); 47 p.count = count; 55 48 56 49 if (!count) 57 50 return; 58 51 59 p. m_properties.set(new SavedProperty[count]);60 61 S avedProperty* prop = p.m_properties.get();62 for ( size_t i = 0; i < count; ++i, ++prop) {63 LocalStorageEntry& entry = d->localStorage[i];64 prop->value = entry.value;65 p rop->attributes = entry.attributes;52 p.properties.set(new SavedProperty[count]); 53 54 SymbolTable::const_iterator end = d->symbolTable->end(); 55 for (SymbolTable::const_iterator it = d->symbolTable->begin(); it != end; ++it) { 56 size_t i = it->second; 57 const LocalStorageEntry& entry = d->localStorage[i]; 58 p.properties[i].init(it->first.get(), entry.value, entry.attributes); 66 59 } 67 60 } 68 61 69 void JSVariableObject::restoreLocalStorage( SavedProperties& p) const62 void JSVariableObject::restoreLocalStorage(const SavedProperties& p) 70 63 { 71 unsigned count = p.m_count; 64 unsigned count = p.count; 65 d->symbolTable->clear(); 72 66 d->localStorage.resize(count); 73 SavedProperty* prop = p.m_properties.get(); 74 for (size_t i = 0; i < count; ++i, ++prop) 75 d->localStorage[i] = LocalStorageEntry(prop->value, prop->attributes); 67 SavedProperty* property = p.properties.get(); 68 for (size_t i = 0; i < count; ++i, ++property) { 69 ASSERT(!d->symbolTable->contains(property->name())); 70 LocalStorageEntry& entry = d->localStorage[i]; 71 d->symbolTable->set(property->name(), i); 72 entry.value = property->value(); 73 entry.attributes = property->attributes(); 74 } 76 75 } 77 76 -
trunk/JavaScriptCore/kjs/JSVariableObject.h
r29818 r29943 1 1 /* 2 * Copyright (C) 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 41 41 LocalStorage& localStorage() { return d->localStorage; } 42 42 43 void saveSymbolTable(SymbolTable& s) const; 44 void restoreSymbolTable(SymbolTable& s) const; 45 46 void saveLocalStorage(SavedProperties& s) const; 47 void restoreLocalStorage(SavedProperties& s) const; 43 void saveLocalStorage(SavedProperties&) const; 44 void restoreLocalStorage(const SavedProperties&); 48 45 49 46 virtual bool deleteProperty(ExecState*, const Identifier&); … … 58 55 struct JSVariableObjectData { 59 56 JSVariableObjectData() { } 60 61 57 JSVariableObjectData(SymbolTable* s) 62 58 : symbolTable(s) // Subclass owns this pointer. … … 66 62 LocalStorage localStorage; // Storage for variables in the symbol table. 67 63 SymbolTable* symbolTable; // Maps name -> index in localStorage. 68 69 64 }; 70 65 … … 107 102 return true; 108 103 } 109 110 104 return false; 111 105 } -
trunk/JavaScriptCore/kjs/LocalStorage.h
r29663 r29943 2 2 /* 3 3 * Copyright (C) 1999-2000 Harri Porten ([email protected]) 4 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.4 * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved. 5 5 * Copyright (C) 2007 Cameron Zwarich ([email protected]) 6 6 * Copyright (C) 2007 Maks Orlovich … … 37 37 } 38 38 39 LocalStorageEntry(JSValue* v, inta)39 LocalStorageEntry(JSValue* v, unsigned a) 40 40 : value(v) 41 41 , attributes(a) … … 44 44 45 45 JSValue* value; 46 intattributes;46 unsigned attributes; 47 47 }; 48 48 -
trunk/JavaScriptCore/kjs/property_map.cpp
r28884 r29943 1 1 /* 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 3 3 * 4 4 * This library is free software; you can redistribute it and/or … … 127 127 128 128 SavedProperties::SavedProperties() 129 : m_count(0)129 : count(0) 130 130 { 131 131 } … … 717 717 } 718 718 719 void PropertyMap::save(SavedProperties &p) const719 void PropertyMap::save(SavedProperties& s) const 720 720 { 721 721 unsigned count = 0; … … 733 733 } 734 734 735 p.m_properties.clear();736 p.m_count = count;735 s.properties.clear(); 736 s.count = count; 737 737 738 738 if (count == 0) 739 739 return; 740 740 741 p.m_properties.set(new SavedProperty [count]); 742 743 SavedProperty* prop = p.m_properties.get(); 744 745 if (!m_usingTable) { 746 #if USE_SINGLE_ENTRY 747 if (m_singleEntryKey && !(m_singleEntryAttributes & (ReadOnly | Function))) { 748 prop->key = Identifier(m_singleEntryKey); 749 prop->value = m_u.singleEntryValue; 750 prop->attributes = m_singleEntryAttributes; 751 ++prop; 752 } 753 #endif 754 } else { 755 // Save in the right order so we don't lose the order. 756 // Another possibility would be to save the indices. 757 758 // Allocate a buffer to use to sort the keys. 759 Vector<Entry*, smallMapThreshold> sortedEntries(count); 760 761 // Get pointers to the entries in the buffer. 762 Entry** p = sortedEntries.data(); 763 unsigned entryCount = m_u.table->keyCount + m_u.table->deletedSentinelCount; 764 for (unsigned i = 1; i <= entryCount; ++i) { 765 if (m_u.table->entries()[i].key && !(m_u.table->entries()[i].attributes & (ReadOnly | Function))) 766 *p++ = &m_u.table->entries()[i]; 767 } 768 ASSERT(p == sortedEntries.data() + count); 769 770 // Sort the entries by index. 771 qsort(sortedEntries.data(), p - sortedEntries.data(), sizeof(Entry*), comparePropertyMapEntryIndices); 772 773 // Put the sorted entries into the saved properties list. 774 for (Entry** q = sortedEntries.data(); q != p; ++q, ++prop) { 775 Entry* e = *q; 776 prop->key = Identifier(e->key); 777 prop->value = e->value; 778 prop->attributes = e->attributes; 779 } 780 } 781 } 782 783 void PropertyMap::restore(const SavedProperties &p) 784 { 785 for (unsigned i = 0; i != p.m_count; ++i) 786 put(p.m_properties[i].key, p.m_properties[i].value, p.m_properties[i].attributes); 741 s.properties.set(new SavedProperty[count]); 742 743 SavedProperty* prop = s.properties.get(); 744 745 #if USE_SINGLE_ENTRY 746 if (!m_usingTable) { 747 prop->init(m_singleEntryKey, m_u.singleEntryValue, m_singleEntryAttributes); 748 return; 749 } 750 #endif 751 752 // Save in the right order so we don't lose the order. 753 // Another possibility would be to save the indices. 754 755 // Allocate a buffer to use to sort the keys. 756 Vector<Entry*, smallMapThreshold> sortedEntries(count); 757 758 // Get pointers to the entries in the buffer. 759 Entry** p = sortedEntries.data(); 760 unsigned entryCount = m_u.table->keyCount + m_u.table->deletedSentinelCount; 761 for (unsigned i = 1; i <= entryCount; ++i) { 762 if (m_u.table->entries()[i].key && !(m_u.table->entries()[i].attributes & (ReadOnly | Function))) 763 *p++ = &m_u.table->entries()[i]; 764 } 765 ASSERT(p == sortedEntries.data() + count); 766 767 // Sort the entries by index. 768 qsort(sortedEntries.data(), p - sortedEntries.data(), sizeof(Entry*), comparePropertyMapEntryIndices); 769 770 // Put the sorted entries into the saved properties list. 771 for (Entry** q = sortedEntries.data(); q != p; ++q, ++prop) { 772 Entry* e = *q; 773 prop->init(e->key, e->value, e->attributes); 774 } 775 } 776 777 void PropertyMap::restore(const SavedProperties& p) 778 { 779 for (unsigned i = 0; i != p.count; ++i) 780 put(Identifier(p.properties[i].name()), p.properties[i].value(), p.properties[i].attributes()); 787 781 } 788 782 -
trunk/JavaScriptCore/kjs/property_map.h
r28884 r29943 1 1 // -*- mode: c++; c-basic-offset: 4 -*- 2 2 /* 3 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 4 4 * 5 5 * This library is free software; you can redistribute it and/or … … 35 35 struct PropertyMapEntry; 36 36 struct PropertyMapHashTable; 37 38 struct SavedProperty { 39 Identifier key; 40 ProtectedPtr<JSValue> value; 41 unsigned attributes; 37 38 class SavedProperty : Noncopyable { 39 public: 40 // Since we use this in arrays, we allocate it uninitialized 41 // and then explicitly initialize. This means we can allocate 42 // the array without initializing every saved property in the 43 // array twice. To accomplish this, the class uses data members 44 // with types that don't have constructors. 45 SavedProperty(); 46 void init(UString::Rep* name, JSValue*, unsigned attributes); 47 ~SavedProperty(); 48 49 UString::Rep* name() const; 50 JSValue* value() const; 51 unsigned attributes() const; 52 53 private: 54 UString::Rep* m_name; 55 JSValue* m_value; 56 unsigned m_attributes; 42 57 }; 43 58 … … 46 61 ~SavedProperties(); 47 62 48 unsigned m_count;49 OwnArrayPtr<SavedProperty> m_properties;63 unsigned count; 64 OwnArrayPtr<SavedProperty> properties; 50 65 }; 51 66 … … 107 122 } 108 123 124 inline SavedProperty::SavedProperty() 125 #ifndef NDEBUG 126 : m_name(0) 127 , m_value(0) 128 , m_attributes(0) 129 #endif 130 { 131 } 132 133 inline void SavedProperty::init(UString::Rep* name, JSValue* value, unsigned attributes) 134 { 135 ASSERT(name); 136 ASSERT(value); 137 138 ASSERT(!m_name); 139 ASSERT(!m_value); 140 ASSERT(!m_attributes); 141 142 m_name = name; 143 m_value = value; 144 m_attributes = attributes; 145 name->ref(); 146 gcProtect(value); 147 } 148 149 inline SavedProperty::~SavedProperty() 150 { 151 ASSERT(m_name); 152 ASSERT(m_value); 153 154 m_name->deref(); 155 gcUnprotect(m_value); 156 } 157 158 inline UString::Rep* SavedProperty::name() const 159 { 160 ASSERT(m_name); 161 ASSERT(m_value); 162 163 return m_name; 164 } 165 166 inline JSValue* SavedProperty::value() const 167 { 168 ASSERT(m_name); 169 ASSERT(m_value); 170 171 return m_value; 172 } 173 174 inline unsigned SavedProperty::attributes() const 175 { 176 ASSERT(m_name); 177 ASSERT(m_value); 178 179 return m_attributes; 180 } 181 109 182 } // namespace 110 183
Note:
See TracChangeset
for help on using the changeset viewer.