Skip to content

Commit

Permalink
Remove SetIdleTaskTime() from ContainerNeedsUpdate(), which cause…
Browse files Browse the repository at this point in the history
…d 2x slowdown for replace all.
  • Loading branch information
zufuliu committed Nov 16, 2023
1 parent 4e872ae commit e9c993c
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions scintilla/src/EditModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ EditModel::EditModel() : durationWrapOneUnit(0.01 / 64), durationWrapOneThread(0
GetNativeSystemInfo(&info);
hardwareConcurrency = info.dwNumberOfProcessors;
idleTaskTimer = CreateWaitableTimer(nullptr, true, nullptr);
SetIdleTaskTime(IdleLineWrapTime);
UpdateParallelLayoutThreshold();
}

Expand Down
1 change: 0 additions & 1 deletion scintilla/src/EditModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class EditModel {
ActionDuration durationWrapOneUnit;
ActionDuration durationWrapOneThread;
static constexpr uint32_t IdleLineWrapTime = 250;
static constexpr uint32_t ActiveLineWrapTime = 500;
void *idleTaskTimer;

EditModel();
Expand Down
7 changes: 5 additions & 2 deletions scintilla/src/EditView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,16 @@ struct LayoutWorker {
}
}

uint32_t Start(Sci::Position posLineStart, uint32_t posInLine) {
uint32_t Start(Sci::Position posLineStart, uint32_t posInLine, LayoutLineOption option) {
const int startPos = ll->lastSegmentEnd;
const int endPos = ll->numCharsInLine;
if (endPos - startPos > blockSize*2 && !model.BidirectionalEnabled()) {
posInLine = std::max<uint32_t>(posInLine, ll->caretPosition) + blockSize;
if (posInLine > static_cast<uint32_t>(endPos)) {
posInLine = endPos;
} else if (option < LayoutLineOption::IdleUpdate) {
// layout as much as possible to avoid unexpected scrolling
model.SetIdleTaskTime(EditModel::IdleLineWrapTime);
}
} else {
posInLine = endPos;
Expand Down Expand Up @@ -663,7 +666,7 @@ uint64_t EditView::LayoutLine(const EditModel &model, Surface *surface, const Vi
//const ElapsedPeriod period;
//posInLine = ll->numCharsInLine; // whole line
LayoutWorker worker{ ll, vstyle, surface, posCache, model, {}};
const uint32_t threadCount = worker.Start(posLineStart, posInLine);
const uint32_t threadCount = worker.Start(posLineStart, posInLine, option);

// Accumulate absolute positions from relative positions within segments and expand tabs
const uint32_t finishedCount = worker.finishedCount.load(std::memory_order_relaxed);
Expand Down
1 change: 1 addition & 0 deletions scintilla/src/EditView.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum class DrawPhase {
enum class LayoutLineOption {
AutoUpdate,
ManualUpdate,
IdleUpdate,
KeepPosition,
Printing,
CallerMultiThreaded = 8,
Expand Down
4 changes: 1 addition & 3 deletions scintilla/src/Editor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ bool Editor::WrapBlock(Surface *surface, Sci::Line lineToWrap, Sci::Line lineToW
} else {
ll->caretPosition = 0;
}
const uint64_t wrappedBytes = view.LayoutLine(*this, surface, vs, ll, wrapWidth, LayoutLineOption::ManualUpdate);
const uint64_t wrappedBytes = view.LayoutLine(*this, surface, vs, ll, wrapWidth, LayoutLineOption::IdleUpdate);
wrappedBytesAllThread += wrappedBytes & UINT32_MAX;
wrappedBytesOneThread += wrappedBytes >> 32;
linesAfterWrap[index] = ll->lines;
Expand Down Expand Up @@ -3014,8 +3014,6 @@ void Editor::NotifyMacroRecord(Message iMessage, uptr_t wParam, sptr_t lParam) n
// Something has changed that the container should know about
void Editor::ContainerNeedsUpdate(Update flags) noexcept {
needUpdateUI = needUpdateUI | flags;
// layout as much as possible inside LayoutLine() to avoid unexpected scrolling
SetIdleTaskTime(ActiveLineWrapTime);
}

/**
Expand Down
1 change: 1 addition & 0 deletions scintilla/win32/ScintillaWin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2351,6 +2351,7 @@ sptr_t ScintillaWin::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
case WM_SETREDRAW:
::DefWindowProc(MainHWND(), msg, wParam, lParam);
if (wParam) {
SetIdleTaskTime(IdleLineWrapTime);
SetScrollBars();
SetVerticalScrollPos();
SetHorizontalScrollPos();
Expand Down

0 comments on commit e9c993c

Please sign in to comment.