Skip to content

Commit

Permalink
Throtteled the various idle events handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
eranif committed Mar 25, 2024
1 parent 58b0700 commit 8825003
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 123 deletions.
11 changes: 4 additions & 7 deletions LiteEditor/cl_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "buildtabsettingsdata.h"
#include "cc_box_tip_window.h"
#include "clEditorStateLocker.h"
#include "clIdleEventThrottler.hpp"
#include "clPrintout.h"
#include "clResizableTooltip.h"
#include "clSFTPManager.hpp"
Expand Down Expand Up @@ -6515,17 +6516,13 @@ void clEditor::OnIdle(wxIdleEvent& event)
}

event.Skip();
std::chrono::milliseconds ms =
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());

// We allow IDLE event once in 100ms
uint64_t current_ts = ms.count();
if ((current_ts - m_lastIdleEvent) < 250) {
// The internval between idle events can not be under 250ms
static clIdleEventThrottler event_throttler{ 250 };
if (!event_throttler.CanHandle()) {
return;
}

m_lastIdleEvent = current_ts;

if (m_scrollbar_recalc_is_required) {
m_scrollbar_recalc_is_required = false;
RecalcHorizontalScrollbar();
Expand Down
7 changes: 7 additions & 0 deletions LiteEditor/mainbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "FilesModifiedDlg.h"
#include "NotebookNavigationDlg.h"
#include "WelcomePage.h"
#include "clIdleEventThrottler.hpp"
#include "clImageViewer.h"
#include "clWorkspaceManager.h"
#include "cl_defs.h"
Expand Down Expand Up @@ -1785,6 +1786,12 @@ void MainBook::OnIdle(wxIdleEvent& event)
{
event.Skip();

// The internval between idle events can not be under 200ms
static clIdleEventThrottler event_throttler{ 200 };
if (!event_throttler.CanHandle()) {
return;
}

// avoid processing if not really needed
if (!m_initDone || (m_book->GetPageCount() == 0)) {
return;
Expand Down
Loading

0 comments on commit 8825003

Please sign in to comment.