[webkit-changes] cvs commit: JavaScriptCore/kjs list.cpp
Darin
darin at opensource.apple.com
Sun Aug 14 09:34:02 PDT 2005
darin 05/08/14 09:34:02
Modified: . ChangeLog
kjs list.cpp
Log:
Reviewed by Maciej.
- fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4419
speed up JavaScript by improving KJS::List
my measurements show an improvement of 1% on iBench JavaScript
* kjs/list.cpp: Rearrange list to make the values and free list share the same storage,
which saves 4 bytes per list. Also remove the pointers used only on the heap from the
lists that are in the pool, which saves 8 bytes per list. Moving the free list pointer
closer to the start of the list object also speeds up access to the free list. New
"HeapListImp" struct is used only for the lists on the heap.
(KJS::List::markProtectedLists): Shadowed global variable in local and updated for the
new terminology ("heap" instead of "outside pool").
(KJS::allocateListImp): Updated for new terminology.
(KJS::List::release): Moved the code from deallocateListImp in here -- it wasn't being
inlined and didn't need to be in a separate function.
Revision Changes Path
1.795 +20 -0 JavaScriptCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
retrieving revision 1.794
retrieving revision 1.795
diff -u -r1.794 -r1.795
--- ChangeLog 14 Aug 2005 16:27:12 -0000 1.794
+++ ChangeLog 14 Aug 2005 16:34:01 -0000 1.795
@@ -2,6 +2,26 @@
Reviewed by Maciej.
+ - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4419
+ speed up JavaScript by improving KJS::List
+
+ my measurements show an improvement of 1% on iBench JavaScript
+
+ * kjs/list.cpp: Rearrange list to make the values and free list share the same storage,
+ which saves 4 bytes per list. Also remove the pointers used only on the heap from the
+ lists that are in the pool, which saves 8 bytes per list. Moving the free list pointer
+ closer to the start of the list object also speeds up access to the free list. New
+ "HeapListImp" struct is used only for the lists on the heap.
+ (KJS::List::markProtectedLists): Shadowed global variable in local and updated for the
+ new terminology ("heap" instead of "outside pool").
+ (KJS::allocateListImp): Updated for new terminology.
+ (KJS::List::release): Moved the code from deallocateListImp in here -- it wasn't being
+ inlined and didn't need to be in a separate function.
+
+2005-08-14 Darin Adler <darin at apple.com>
+
+ Reviewed by Maciej.
+
- fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4417
speed up JavaScript with some small changes to the property map code
1.15 +46 -43 JavaScriptCore/kjs/list.cpp
Index: list.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/kjs/list.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- list.cpp 8 Aug 2005 04:07:28 -0000 1.14
+++ list.cpp 14 Aug 2005 16:34:02 -0000 1.15
@@ -31,19 +31,18 @@
const int poolSize = 512;
const int inlineValuesSize = 4;
-
enum ListImpState { unusedInPool = 0, usedInPool, usedOnHeap, immortal };
struct ListImp : ListImpBase
{
ListImpState state;
- ValueImp *values[inlineValuesSize];
int capacity;
ValueImp **overflow;
- ListImp *nextInFreeList;
- ListImp *nextInOutsideList;
- ListImp *prevInOutsideList;
+ union {
+ ValueImp *values[inlineValuesSize];
+ ListImp *nextInFreeList;
+ };
#if DUMP_STATISTICS
int sizeHighWaterMark;
@@ -52,9 +51,15 @@
void markValues();
};
+struct HeapListImp : ListImp
+{
+ HeapListImp *nextInHeapList;
+ HeapListImp *prevInHeapList;
+};
+
static ListImp pool[poolSize];
static ListImp *poolFreeList;
-static ListImp *outsidePoolList;
+static HeapListImp *heapList;
static int poolUsed;
#if DUMP_STATISTICS
@@ -112,10 +117,9 @@
void List::markProtectedLists()
{
int seen = 0;
- for (int i = 0; i < poolSize; i++) {
- if (seen >= poolUsed)
- break;
+ int used = poolUsed;
+ for (int i = 0; i < poolSize && seen < used; i++) {
if (pool[i].state == usedInPool) {
seen++;
if (pool[i].valueRefCount > 0) {
@@ -124,7 +128,7 @@
}
}
- for (ListImp *l = outsidePoolList; l; l = l->nextInOutsideList) {
+ for (HeapListImp *l = heapList; l; l = l->nextInHeapList) {
if (l->valueRefCount > 0) {
l->markValues();
}
@@ -143,44 +147,19 @@
return imp;
}
- ListImp *imp = new ListImp;
+ HeapListImp *imp = new HeapListImp;
imp->state = usedOnHeap;
- // link into outside pool list
- if (outsidePoolList) {
- outsidePoolList->prevInOutsideList = imp;
+ // link into heap list
+ if (heapList) {
+ heapList->prevInHeapList = imp;
}
- imp->nextInOutsideList = outsidePoolList;
- imp->prevInOutsideList = NULL;
- outsidePoolList = imp;
+ imp->nextInHeapList = heapList;
+ imp->prevInHeapList = NULL;
+ heapList = imp;
return imp;
}
-static inline void deallocateListImp(ListImp *imp)
-{
- if (imp->state == usedInPool) {
- imp->state = unusedInPool;
- imp->nextInFreeList = poolFreeList;
- poolFreeList = imp;
- poolUsed--;
- } else {
- // unlink from outside pool list
- if (!imp->prevInOutsideList) {
- outsidePoolList = imp->nextInOutsideList;
- if (outsidePoolList) {
- outsidePoolList->prevInOutsideList = NULL;
- }
- } else {
- imp->prevInOutsideList->nextInOutsideList = imp->nextInOutsideList;
- if (imp->nextInOutsideList) {
- imp->nextInOutsideList->prevInOutsideList = imp->prevInOutsideList;
- }
- }
-
- delete imp;
- }
-}
-
List::List() : _impBase(allocateListImp()), _needsMarking(false)
{
ListImp *imp = static_cast<ListImp *>(_impBase);
@@ -230,7 +209,31 @@
#endif
delete [] imp->overflow;
- deallocateListImp(imp);
+
+ if (imp->state == usedInPool) {
+ imp->state = unusedInPool;
+ imp->nextInFreeList = poolFreeList;
+ poolFreeList = imp;
+ poolUsed--;
+ } else {
+ assert(imp->state == usedOnHeap);
+ HeapListImp *list = static_cast<HeapListImp *>(imp);
+
+ // unlink from heap list
+ if (!list->prevInHeapList) {
+ heapList = list->nextInHeapList;
+ if (heapList) {
+ heapList->prevInHeapList = NULL;
+ }
+ } else {
+ list->prevInHeapList->nextInHeapList = list->nextInHeapList;
+ if (list->nextInHeapList) {
+ list->nextInHeapList->prevInHeapList = list->prevInHeapList;
+ }
+ }
+
+ delete list;
+ }
}
ValueImp *List::at(int i) const
More information about the webkit-changes
mailing list