From 1185dba838947d9a99e0fd773453e2b92e9c3dbd Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sun, 28 Oct 2007 13:51:01 +0100 Subject: [PATCH] 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). --- src/MacVim/MMBackend.m | 3 +++ src/MacVim/gui_macvim.m | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index edc1c773..d4437649 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -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; } diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 454e4855..b43f7850 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -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]; } -- 2.11.4.GIT