Skip to content

Commit

Permalink
Remove polling, optimise find file, more logging
Browse files Browse the repository at this point in the history
1. Experimental: removed constant polling from the main thread.
   This should noticeably reduce CPU consumption and make various idle events more predictable.

2. Experimental: reworked Find File dialog updating.
   This should make the search faster and make UI updates more predictable.

3. Optimisation of message transfer between threads.
   This should reduce the amount of locks and make things faster in various places.

4. More logging.

5. Minor refactoring.
  • Loading branch information
alabuzhev committed May 27, 2021
1 parent 41b5f54 commit 56ef594
Show file tree
Hide file tree
Showing 21 changed files with 283 additions and 196 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*.{c,cpp,h,hpp}]
charset = utf-8-bom
indent_style = tab
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
2 changes: 2 additions & 0 deletions far/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[{plugin,res}.hpp]
charset = utf-8
13 changes: 13 additions & 0 deletions far/.vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "1.0",
"components": [
"Microsoft.Component.MSBuild",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Component.VC.CoreIde",
"Microsoft.VisualStudio.Workload.NativeDesktop",
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.Component.Windows10SDK.18362"
]
}
20 changes: 20 additions & 0 deletions far/cddrv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cddrv.hpp"

// Internal:
#include "exception.hpp"
#include "log.hpp"
#include "pathmix.hpp"

// Platform:
Expand Down Expand Up @@ -230,7 +232,10 @@ static auto capatibilities_from_scsi_configuration(const os::fs::file& Device)
Spt.CdbLength = CDB10GENERIC_LENGTH;

if (!Device.IoControl(IOCTL_SCSI_PASS_THROUGH, &Spt, sizeof(SCSI_PASS_THROUGH), &Spt, sizeof(Spt)) || Spt.ScsiStatus != SCSISTAT_GOOD)
{
LOGWARNING(L"SCSIOP_GET_CONFIGURATION: {}"sv, last_error());
return CAPABILITIES_NONE;
}

span const Buffer(Spt.DataBuf, Spt.DataTransferLength);

Expand Down Expand Up @@ -267,7 +272,10 @@ static auto capatibilities_from_scsi_mode_sense(const os::fs::file& Device)
Spt.CdbLength = CDB6GENERIC_LENGTH;

if (!Device.IoControl(IOCTL_SCSI_PASS_THROUGH, &Spt, sizeof(SCSI_PASS_THROUGH), &Spt, sizeof(Spt)) || Spt.ScsiStatus != SCSISTAT_GOOD)
{
LOGWARNING(L"SCSIOP_MODE_SENSE: {}"sv, last_error());
return CAPABILITIES_NONE;
}

const auto& CapsPage = view_as<CDVD_CAPABILITIES_PAGE>(Spt.DataBuf + sizeof(MODE_PARAMETER_HEADER));

Expand Down Expand Up @@ -363,11 +371,17 @@ static auto capatibilities_from_product_id(const os::fs::file& Device)
STORAGE_PROPERTY_QUERY PropertyQuery{ StorageDeviceProperty, PropertyStandardQuery };

if (!Device.IoControl(IOCTL_STORAGE_QUERY_PROPERTY, &PropertyQuery, sizeof(PropertyQuery), &DescriptorHeader, sizeof(DescriptorHeader)) || !DescriptorHeader.Size)
{
LOGWARNING(L"IOCTL_STORAGE_QUERY_PROPERTY: {}"sv, last_error());
return CAPABILITIES_NONE;
}

const char_ptr_n<os::default_buffer_size> Buffer(DescriptorHeader.Size);
if (!Device.IoControl(IOCTL_STORAGE_QUERY_PROPERTY, &PropertyQuery, sizeof(PropertyQuery), Buffer.data(), static_cast<DWORD>(Buffer.size())))
{
LOGWARNING(L"IOCTL_STORAGE_QUERY_PROPERTY: {}"sv, last_error());
return CAPABILITIES_NONE;
}

const auto& DeviceDescriptor = view_as<STORAGE_DEVICE_DESCRIPTOR>(Buffer.data());

Expand Down Expand Up @@ -461,11 +475,17 @@ bool is_removable_usb(string_view RootDir)

const auto Device = os::fs::file(drive, STANDARD_RIGHTS_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING);
if (!Device)
{
LOGWARNING(L"CreateFile({}): {}"sv, drive, last_error());
return false;
}

DISK_GEOMETRY DiskGeometry;
if (!Device.IoControl(IOCTL_DISK_GET_DRIVE_GEOMETRY, nullptr, 0, &DiskGeometry, sizeof(DiskGeometry)))
{
LOGWARNING(L"IOCTL_DISK_GET_DRIVE_GEOMETRY({}): {}"sv, drive, last_error());
return false;
}

return DiskGeometry.MediaType == FixedMedia || DiskGeometry.MediaType == RemovableMedia;
}
Expand Down
16 changes: 16 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
--------------------------------------------------------------------------------
drkns 27.05.2021 23:22:21 +0100 - build 5804

1. Experimental: removed constant polling from the main thread.
This should noticeably reduce CPU consumption and make various idle events more predictable.

2. Experimental: reworked Find File dialog updating.
This should make the search faster and make UI updates more predictable.

3. Optimisation of message transfer between threads.
This should reduce the amount of locks and make things faster in various places.

4. More logging.

5. Minor refactoring.

--------------------------------------------------------------------------------
drkns 27.05.2021 17:18:25 +0100 - build 5803

Expand Down
47 changes: 38 additions & 9 deletions far/clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "console.hpp"
#include "encoding.hpp"
#include "eol.hpp"
#include "exception.hpp"
#include "log.hpp"

// Platform:
#include "platform.chrono.hpp"
Expand Down Expand Up @@ -119,7 +121,10 @@ class system_clipboard: public clipboard, public singleton<system_clipboard>
return true;

if (!CloseClipboard())
{
LOGWARNING(L"CloseClipboard(): {}"sv, last_error());
return false;
}

m_Opened = false;
return true;
Expand Down Expand Up @@ -147,7 +152,10 @@ class system_clipboard: public clipboard, public singleton<system_clipboard>
assert(m_Opened);

if (!SetClipboardData(Format, Data.get()))
{
LOGWARNING(L"SetClipboardData(): {}"sv, last_error());
return false;
}

// Owned by the OS now
(void)Data.release();
Expand All @@ -172,13 +180,17 @@ class system_clipboard: public clipboard, public singleton<system_clipboard>
if (!FormatId)
{
FormatId = RegisterClipboardFormat(FormatName);
if (!FormatId)
{
LOGWARNING(L"RegisterClipboardFormat(): {}"sv, last_error());
}
}
return FormatId;
}

bool IsFormatAvailable(unsigned Format) const override
{
return IsClipboardFormatAvailable(Format) != FALSE;
return Format && IsClipboardFormatAvailable(Format);
}
};

Expand Down Expand Up @@ -307,7 +319,8 @@ bool clipboard::SetText(const string_view Str)

// 'Notepad++ binary text length'
// return value is ignored - non-critical feature
SetData(RegisterFormat(clipboard_format::notepad_plusplus_binary_text_length), os::memory::global::copy(static_cast<uint32_t>(Str.size())));
if (const auto Format = RegisterFormat(clipboard_format::notepad_plusplus_binary_text_length))
SetData(Format, os::memory::global::copy(static_cast<uint32_t>(Str.size())));

// return value is ignored - non-critical feature
if (auto Locale = os::memory::global::copy(GetUserDefaultLCID()))
Expand All @@ -322,7 +335,6 @@ bool clipboard::SetVText(const string_view Str)
return false;

const auto FarVerticalBlock = RegisterFormat(clipboard_format::vertical_block_unicode);

if (!FarVerticalBlock)
return false;

Expand All @@ -331,11 +343,13 @@ bool clipboard::SetVText(const string_view Str)

// 'Borland IDE Block Type'
// return value is ignored - non-critical feature
SetData(RegisterFormat(clipboard_format::borland_ide_dev_block), os::memory::global::copy('\x02'));
if (const auto Format = RegisterFormat(clipboard_format::borland_ide_dev_block))
SetData(Format, os::memory::global::copy('\x02'));

// 'MSDEVColumnSelect'
// return value is ignored - non-critical feature
SetData(RegisterFormat(clipboard_format::ms_dev_column_select), os::memory::global::copy(0));
if (const auto Format = RegisterFormat(clipboard_format::ms_dev_column_select))
SetData(Format, os::memory::global::copy(0));

return true;
}
Expand Down Expand Up @@ -370,7 +384,10 @@ bool clipboard::SetHDROP(const string_view NamesData, const bool bMoved)
if (!hMemoryMove)
return false;

return SetData(RegisterFormat(clipboard_format::preferred_drop_effect), std::move(hMemoryMove));
if (const auto Format = RegisterFormat(clipboard_format::preferred_drop_effect))
return SetData(Format, std::move(hMemoryMove));

return false;
}

bool clipboard::GetText(string& Data) const
Expand All @@ -385,7 +402,11 @@ bool clipboard::GetText(string& Data) const

const auto GetBinaryTextLength = [this]
{
const auto hClipDataLen = GetData(RegisterFormat(clipboard_format::notepad_plusplus_binary_text_length));
const auto Format = RegisterFormat(clipboard_format::notepad_plusplus_binary_text_length);
if (!Format)
return string::npos;

const auto hClipDataLen = GetData(Format);
if (!hClipDataLen)
return string::npos;

Expand Down Expand Up @@ -435,7 +456,11 @@ bool clipboard::GetVText(string& Data) const
{
const auto IsBorlandVerticalBlock = [this]
{
const auto hClipData = GetData(RegisterFormat(clipboard_format::borland_ide_dev_block));
const auto Format = RegisterFormat(clipboard_format::borland_ide_dev_block);
if (!Format)
return false;

const auto hClipData = GetData(Format);
if (!hClipData)
return false;

Expand All @@ -450,7 +475,11 @@ bool clipboard::GetVText(string& Data) const
return GetText(Data);
}

const auto hClipData = GetData(RegisterFormat(clipboard_format::vertical_block_oem));
const auto Format = RegisterFormat(clipboard_format::vertical_block_oem);
if (!Format)
return false;

const auto hClipData = GetData(Format);
if (!hClipData)
return false;

Expand Down
7 changes: 3 additions & 4 deletions far/configdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1811,12 +1811,11 @@ class HistoryConfigCustom: public HistoryConfig, public sqlite_boilerplate
bool bAddDelete=false, bCommit=false;

{
SCOPED_ACTION(auto)(WorkQueue.scoped_lock());

decltype(WorkQueue)::value_type item;
while (WorkQueue.try_pop(item))
for (auto Messages = WorkQueue.pop_all(); !Messages.empty(); Messages.pop())
{
SCOPE_EXIT{ SQLiteDb::EndTransaction(); };

auto& item = Messages.front();
if (item) //DeleteAndAddAsync
{
SQLiteDb::BeginTransaction();
Expand Down
4 changes: 2 additions & 2 deletions far/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void Edit::FastShow(const ShowInfo* Info)
Text(fit_to_left(OutStr, EditLength));

if (m_Flags.Check(FEDITLINE_EDITORMODE))
ApplyColor(GetSelectedColor(), XPos, FocusedLeftPos);
ApplyColor(XPos, FocusedLeftPos);

if (TabSelStart==-1)
{
Expand Down Expand Up @@ -2073,7 +2073,7 @@ bool Edit::GetColor(ColorItem& col, size_t Item) const
return true;
}

void Edit::ApplyColor(const FarColor& SelColor, int XPos, int FocusedLeftPos)
void Edit::ApplyColor(int XPos, int FocusedLeftPos)
{
// Для оптимизации сохраняем вычисленные позиции между итерациями цикла
int Pos = INT_MIN, TabPos = INT_MIN, TabEditorPos = INT_MIN;
Expand Down
2 changes: 1 addition & 1 deletion far/edit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Edit: public SimpleScreenObject

bool InsertKey(wchar_t Key);
bool RecurseProcessKey(int Key);
void ApplyColor(const FarColor& SelColor, int XPos, int FocusedLeftPos);
void ApplyColor(int XPos, int FocusedLeftPos);
int GetNextCursorPos(int Position,int Where) const;
static bool CharInMask(wchar_t Char, wchar_t Mask);
bool ProcessCtrlQ();
Expand Down
Loading

0 comments on commit 56ef594

Please sign in to comment.