Enhance large file loading: disable 4 features for large files

Dur to the performaance issue, the loading of large files will disable automatically the following feature:
1. auto-completion (only for large files)
2. snapshot periode backup (only for large files)
3. backup on save (only for large files)
4. word wrap (persistent for all files. Need to enable it manually)

Ref: https://community.notepad-plus-plus.org/topic/22438/notepad-v8-2-2-release-candidate/6?_=1643194615292

Fix #8802
This commit is contained in:
Don Ho 2022-01-27 16:12:50 +01:00
parent edabe44000
commit 44004d41d4
4 changed files with 38 additions and 15 deletions

View File

@ -1499,7 +1499,7 @@ bool Notepad_plus::fileSave(BufferID id)
const NppGUI & nppgui = (NppParameters::getInstance()).getNppGUI();
BackupFeature backup = nppgui._backup;
if (backup != bak_none)
if (backup != bak_none && !buf->isLargeFile())
{
const TCHAR *fn = buf->getFullPathName();
TCHAR *name = ::PathFindFileName(fn);

View File

@ -660,11 +660,15 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (indentMaintain)
maintainIndentation(static_cast<TCHAR>(notification->ch));
AutoCompletion * autoC = isFromPrimary ? &_autoCompleteMain : &_autoCompleteSub;
bool isColumnMode = _pEditView->execute(SCI_GETSELECTIONS) > 1; // Multi-Selection || Column mode)
if (nppGui._matchedPairConf.hasAnyPairsPair() && !isColumnMode)
autoC->insertMatchedChars(notification->ch, nppGui._matchedPairConf);
autoC->update(notification->ch);
Buffer* currentBuf = _pEditView->getCurrentBuffer();
if (!currentBuf->isLargeFile())
{
AutoCompletion* autoC = isFromPrimary ? &_autoCompleteMain : &_autoCompleteSub;
bool isColumnMode = _pEditView->execute(SCI_GETSELECTIONS) > 1; // Multi-Selection || Column mode)
if (nppGui._matchedPairConf.hasAnyPairsPair() && !isColumnMode)
autoC->insertMatchedChars(notification->ch, nppGui._matchedPairConf);
autoC->update(notification->ch);
}
}
break;
}

View File

@ -654,11 +654,26 @@ BufferID FileManager::loadFile(const TCHAR* filename, Document doc, int encoding
int64_t fileSize = _ftelli64(fp);
fclose(fp);
// * the auto-completion feature will be disabled for large files
// * the session snapshotsand periodic backups feature will be disabled for large files
// * the backups on save feature will be disabled for large files
bool isLargeFile = fileSize >= NPP_STYLING_FILESIZE_LIMIT;
// Due to the performance issue, the Word Wrap feature will be disabled if it's ON
if (isLargeFile)
{
bool isWrap = _pNotepadPlus->_pEditView->isWrap();
if (isWrap)
{
_pNotepadPlus->command(IDM_VIEW_WRAP);
}
}
bool ownDoc = false;
if (!doc)
{
// If file exceeds 200MB, activate large file mode
doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT, 0, fileSize < NPP_STYLING_FILESIZE_LIMIT ? 0 : SC_DOCUMENTOPTION_STYLES_NONE | SC_DOCUMENTOPTION_TEXT_LARGE);
doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT, 0, isLargeFile ? SC_DOCUMENTOPTION_STYLES_NONE | SC_DOCUMENTOPTION_TEXT_LARGE : 0);
ownDoc = true;
}
@ -706,6 +721,8 @@ BufferID FileManager::loadFile(const TCHAR* filename, Document doc, int encoding
if (res != 0) // res == 1 or res == -1
newBuf->_timeStamp = fileNameTimestamp;
newBuf->_isLargeFile = isLargeFile;
_buffers.push_back(newBuf);
++_nbBufs;
Buffer* buf = _buffers.at(_nbBufs - 1);
@ -893,9 +910,12 @@ std::mutex backup_mutex;
bool FileManager::backupCurrentBuffer()
{
Buffer* buffer = _pNotepadPlus->getCurrentBuffer();
if (buffer->isLargeFile())
return false;
std::lock_guard<std::mutex> lock(backup_mutex);
Buffer* buffer = _pNotepadPlus->getCurrentBuffer();
bool result = false;
bool hasModifForSession = false;
@ -1387,18 +1407,13 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const TCHAR * fil
int res = pNativeSpeaker->messageBox("WantToOpenHugeFile",
_pNotepadPlus->_pEditView->getHSelf(),
TEXT("Opening a huge file of 2GB+ could take several minutes.\nDo you want to open it?\n(Due to the performance issue, the Word Wrap feature will be disabled if it's ON)"),
TEXT("Opening a huge file of 2GB+ could take several minutes.\nDo you want to open it?"),
TEXT("Opening huge file warning"),
MB_YESNO | MB_APPLMODAL);
if (res == IDYES)
{
// Due to the performance issue, the Word Wrap feature will be disabled if it's ON
bool isWrap = _pNotepadPlus->_pEditView->isWrap();
if (isWrap)
{
_pNotepadPlus->command(IDM_VIEW_WRAP);
}
// Do nothing
}
else
{

View File

@ -292,6 +292,8 @@ public:
bool isUnsync() const { return _isUnsync; }
void setUnsync(bool val) { _isUnsync = val; }
bool isLargeFile() const { return _isLargeFile; }
void startMonitoring() {
_isMonitoringOn = true;
_eventHandle = ::CreateEvent(nullptr, TRUE, FALSE, nullptr);
@ -344,6 +346,7 @@ private:
bool _isUserReadOnly = false;
bool _needLexer = false; // new buffers do not need lexing, Scintilla takes care of that
//these properties have to be duplicated because of multiple references
//All the vectors must have the same size at all times
std::vector<ScintillaEditView *> _referees; // Instances of ScintillaEditView which contain this buffer
std::vector<Position> _positions;
@ -372,6 +375,7 @@ private:
// 2. the file is modified by another app but the buffer is not reloaded in Notepad++.
// Note that if the buffer is untitled, there's no correspondent file on the disk so the buffer is considered as independent therefore synchronized.
bool _isLargeFile = false; // The loading of huge files will disable automatically 1. auto-completion 2. snapshot periode backup 3. backup on save 4. word wrap
// For the monitoring
HANDLE _eventHandle = nullptr;