adium 3433:a96bd47113d7: Finished fixing the nasty performance h...

commits at adium.im commits at adium.im
Sat Oct 30 02:30:32 UTC 2010


details:	http://hg.adium.im/adium/rev/a96bd47113d7
revision:	3433:a96bd47113d7
author:		Evan Schoenberg
date:		Fri Oct 29 21:24:47 2010 -0500

Finished fixing the nasty performance hit I introduced while fixing the AIProxyListObject crash... and which was therefore found in 1.4b20 and later.
(transplanted from ac43384c6b1c0beb589483603ea3add047270334)
(transplanted from 3f99ca0537a7a81a7ebb6ea97f7ae6f19ccf368b)

diffs (167 lines):

diff -r 53d1b23deb2d -r a96bd47113d7 Frameworks/Adium Framework/Source/AIContactObserverManager.h
--- a/Frameworks/Adium Framework/Source/AIContactObserverManager.h	Thu Oct 28 21:21:09 2010 -0500
+++ b/Frameworks/Adium Framework/Source/AIContactObserverManager.h	Fri Oct 29 21:24:47 2010 -0500
@@ -31,7 +31,7 @@
 	NSInteger				delayedAttributeChanges;
 	NSMutableSet			*delayedModifiedAttributeKeys;
 
-	BOOL						updatesAreDelayed;
+	BOOL					updatesAreDelayedUntilInactivity;
 	NSMutableSet			*changedObjects;
 	
 	BOOL						informingObservers;
@@ -47,8 +47,8 @@
 - (void)delayListObjectNotifications;
 - (void)endListObjectNotificationsDelay;
 - (void)endListObjectNotificationsDelaysImmediately;
- at property (readonly, nonatomic) BOOL updatesAreDelayed;
 - (void)delayListObjectNotificationsUntilInactivity;
+- (BOOL)shouldDelayUpdates;
 - (void)listObjectStatusChanged:(AIListObject *)inObject modifiedStatusKeys:(NSSet *)inModifiedKeys silent:(BOOL)silent;
 - (void)listObjectAttributesChanged:(AIListObject *)inObject modifiedKeys:(NSSet *)inModifiedKeys;
 - (void)updateListContactStatus:(AIListContact *)inContact;
diff -r 53d1b23deb2d -r a96bd47113d7 Frameworks/Adium Framework/Source/AIContactObserverManager.m
--- a/Frameworks/Adium Framework/Source/AIContactObserverManager.m	Thu Oct 28 21:21:09 2010 -0500
+++ b/Frameworks/Adium Framework/Source/AIContactObserverManager.m	Fri Oct 29 21:24:47 2010 -0500
@@ -63,7 +63,7 @@
 		delayedModifiedAttributeKeys = [[NSMutableSet alloc] init];
 		delayedContactChanges = 0;
 		delayedUpdateRequests = 0;
-		updatesAreDelayed = NO;		
+		updatesAreDelayedUntilInactivity = NO;
 	}
 	
 	return self;
@@ -84,6 +84,20 @@
 @synthesize delayedUpdateTimer;
 
 /*!
+ * @brief Should potentially expensive updates be deferred?
+ *
+ * Returns YES if, for any reason, now is just not the time to speak up.
+ *
+ * This could be YES because delayListObjectNotifications has been called without endListObjectNotificationsDelay being
+ * called yet, or because delayListObjectNotificationsUntilInactivity was called at least once and we haven't had a
+ * period of inactivity yet.
+ */
+- (BOOL)shouldDelayUpdates
+{
+	return ((delayedUpdateRequests > 0) || updatesAreDelayedUntilInactivity);
+}
+
+/*!
  * @brief Delay notifications for listObject changes until a matching endListObjectNotificationsDelay is called.
  *
  * This delays Contact_ListChanged, ListObject_AttributesChanged, Contact_OrderChanged notificationsDelays,
@@ -95,8 +109,6 @@
 - (void)delayListObjectNotifications
 {
 	delayedUpdateRequests++;
-
-	updatesAreDelayed = YES;
 }
 
 /*!
@@ -109,7 +121,7 @@
 {
 	if (delayedUpdateRequests > 0) {
 		delayedUpdateRequests--;
-		if (delayedUpdateRequests == 0)
+		if ([self shouldDelayUpdates])
 			[self _performDelayedUpdates:nil];
 	}
 }
@@ -130,7 +142,7 @@
 {
 	AILogWithSignature(@"");
 
-	if (delayedUpdateRequests) {
+	if ([self shouldDelayUpdates]) {
 		delayedUpdateRequests = 0;
 
 		BOOL restoreDelayUntilInactivity = (self.delayedUpdateTimer != nil);
@@ -146,14 +158,12 @@
 	}
 }
 
- at synthesize updatesAreDelayed;
-
 //Delay all list object notifications until a period of inactivity occurs.  This is useful for accounts that do not
 //know when they have finished connecting but still want to mute events.
 - (void)delayListObjectNotificationsUntilInactivity
 {
     if (!delayedUpdateTimer) {
-		updatesAreDelayed = YES;
+		updatesAreDelayedUntilInactivity = YES;
 		self.delayedUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:UPDATE_CLUMP_INTERVAL
 																   target:self
 																 selector:@selector(_performDelayedUpdates:)
@@ -197,7 +207,7 @@
 	modifiedAttributeKeys = [self _informObserversOfObjectStatusChange:inObject withKeys:inModifiedKeys silent:silent];
 	
     //Resort the contact list
-	if (updatesAreDelayed) {
+	if ([self shouldDelayUpdates]) {
 		delayedStatusChanges++;
 		[delayedModifiedStatusKeys unionSet:inModifiedKeys];
 	} else {
@@ -218,7 +228,7 @@
 //(When modifying display attributes in response to a status change, this is not necessary)
 - (void)listObjectAttributesChanged:(AIListObject *)inObject modifiedKeys:(NSSet *)inModifiedKeys
 {
-	if (updatesAreDelayed) {
+	if ([self shouldDelayUpdates]) {
 		delayedAttributeChanges++;
 		[delayedModifiedAttributeKeys unionSet:inModifiedKeys];
 	} else {
@@ -242,6 +252,8 @@
 {
 	BOOL	updatesOccured = (delayedStatusChanges || delayedAttributeChanges || delayedContactChanges);
 	
+	static int updatesDone = 0;
+	
 	//Send out global attribute & status changed notifications (to cover any delayed updates)
 	if (updatesOccured) {
 		BOOL shouldSort = NO;
@@ -280,9 +292,7 @@
 		if (delayedUpdateTimer) {
 			[delayedUpdateTimer invalidate];
 			self.delayedUpdateTimer = nil;
-		}
-		if (delayedUpdateRequests == 0) {
-			updatesAreDelayed = NO;
+			updatesAreDelayedUntilInactivity = NO;
 		}
     }
 
@@ -450,6 +460,9 @@
 	informingObservers = NO;
 }
 
+/*!
+ * @brief Keep track of a contact who needs to be resorted whenever we're no longer delaying updates.
+ */
 - (void)noteContactChanged:(AIListObject *)inObject;
 {
 	if (!changedObjects)
diff -r 53d1b23deb2d -r a96bd47113d7 Source/AIContactController.m
--- a/Source/AIContactController.m	Thu Oct 28 21:21:09 2010 -0500
+++ b/Source/AIContactController.m	Fri Oct 29 21:24:47 2010 -0500
@@ -369,7 +369,7 @@
 //Post a list grouping changed notification for the object and containing object
 - (void)_didChangeContainer:(AIListObject<AIContainingObject> *)inContainingObject object:(AIListObject *)object
 {
-	if ([contactPropertiesObserverManager updatesAreDelayed]) {
+	if ([contactPropertiesObserverManager shouldDelayUpdates]) {
 		[contactPropertiesObserverManager noteContactChanged:object];
 
 	} else {
@@ -1071,7 +1071,7 @@
 //Sort an individual object
 - (void)sortListObject:(AIListObject *)inObject
 {
-	if ([contactPropertiesObserverManager updatesAreDelayed]) {
+	if ([contactPropertiesObserverManager shouldDelayUpdates]) {
 		[contactPropertiesObserverManager noteContactChanged:inObject];
 
 	} else {




More information about the commits mailing list