From 6421f275286b3238fe1a7a5e909225251f3e8dbf Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Thu, 8 Jan 2015 01:28:58 +0100 Subject: Replace InternalClass transitions hash with a sorted vector. In a reasonable test application, there were some 1697 transition entries. Out of these, 1663 of them had only a single item. The remainder, with the exception of three, had <10 items. Only one of these had a count of >50 items (86). As can be seen, most of the time, transitions is usually quite sparsely populated, so using a hash is a large amount of overhead considering there's just a few elements. For the times when it isn't, the vector being sorted should help take care of that. Since transitions are never removed, we can use a similar trick to ba690fb73864915b4a35bbec5b7dc134ff1dafd0 and use a sorted vector to store them. Compared to the hash approach, this saved ~412kb according to malloc_stats on a reasonably comprehensive test application. Coincidentally, this also improved v8bench for me by ~10%. Note that this undoes 132cdfa69cae45d0c02ea715ce58722bbcd57e73, but the expectation is that the fewer allocations done by using a vector will outweigh the need to reserve any specific allocation initially. Change-Id: Iec57a7db7e9a60347c9683b1cb1598f6d9c866f7 Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4internalclass_p.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/qml/jsruntime/qv4internalclass_p.h') diff --git a/src/qml/jsruntime/qv4internalclass_p.h b/src/qml/jsruntime/qv4internalclass_p.h index 4367f6576d..5973ca2c7c 100644 --- a/src/qml/jsruntime/qv4internalclass_p.h +++ b/src/qml/jsruntime/qv4internalclass_p.h @@ -193,6 +193,7 @@ struct InternalClassTransition Identifier *id; const ManagedVTable *vtable; }; + InternalClass *lookup; int flags; enum { // range 0-0xff is reserved for attribute changes @@ -201,8 +202,10 @@ struct InternalClassTransition bool operator==(const InternalClassTransition &other) const { return id == other.id && flags == other.flags; } + + bool operator<(const InternalClassTransition &other) const + { return id < other.id; } }; -uint qHash(const QV4::InternalClassTransition &t, uint = 0); struct InternalClass : public QQmlJS::Managed { ExecutionEngine *engine; @@ -213,7 +216,8 @@ struct InternalClass : public QQmlJS::Managed { SharedInternalClassData propertyData; typedef InternalClassTransition Transition; - QHash transitions; // id to next class, positive means add, negative delete + std::vector transitions; + InternalClassTransition &lookupOrInsertTransition(const InternalClassTransition &t); InternalClass *m_sealed; InternalClass *m_frozen; -- cgit v1.2.3