Optimize speed when 'matchparen' is enabled.

When matchparen is used gui_mch_update() gets called a lot.  This function
checks the run loop for new input which takes a long time.  To speed things up
make sure that the run loop is only checked every 100 ms or so (controlled by
MMUpdateTimeoutInterval in gui_macvim.m).
This commit is contained in:
Bjorn Winckler
2007-10-28 13:51:01 +01:00
parent 3d98b6f1f5
commit 75b61c87cf
2 changed files with 39 additions and 0 deletions
+3
View File
@@ -425,6 +425,9 @@ enum {
BOOL yn = inputReceived;
inputReceived = NO;
if ([inputQueue count] > 0)
[self processInputQueue];
//NSLog(@"|LEAVE| %s input=%d", _cmd, yn);
return yn;
}
+36
View File
@@ -14,9 +14,16 @@
#import "vim.h"
// This constant controls how often [MMBackend update] may get called (see
// gui_mch_update()).
static NSTimeInterval MMUpdateTimeoutInterval = 0.1f;
static BOOL gui_macvim_is_valid_action(NSString *action);
// -- Initialization --------------------------------------------------------
/*
@@ -128,10 +135,39 @@ gui_mch_open(void)
* nothing in the X event queue (& no timers pending), then we return
* immediately.
*/
#define MM_LOG_UPDATE_STATS 0
void
gui_mch_update(void)
{
// NOTE: This function can get called A LOT (~1 call/ms) and unfortunately
// checking the run loop takes a long time, resulting in noticable slow
// downs if it is done every time this function is called. Therefore we
// make sure that it is not done too often.
static NSDate *lastUpdateDate = nil;
#if MM_LOG_UPDATE_STATS
static int skipCount = 0;
#endif
if (lastUpdateDate && -[lastUpdateDate timeIntervalSinceNow] <
MMUpdateTimeoutInterval) {
#if MM_LOG_UPDATE_STATS
++skipCount;
#endif
return;
}
#if MM_LOG_UPDATE_STATS
NSTimeInterval dt = -[lastUpdateDate timeIntervalSinceNow];
NSLog(@"Updating (last update %.2f seconds ago, skipped %d updates, "
"approx %.1f calls per second)",
dt, skipCount, dt > 0 ? skipCount/dt : 0);
skipCount = 0;
#endif
[[MMBackend sharedInstance] update];
[lastUpdateDate release];
lastUpdateDate = [[NSDate date] retain];
}