Official eMule-Board: Optimization: Faster Category Switch & Update - Official eMule-Board

Jump to content


Page 1 of 1

Optimization: Faster Category Switch & Update

#1 User is offline   BuyukBang 

  • Member
  • PipPip
  • Group: Members
  • Posts: 36
  • Joined: 04-May 23

Posted 17 May 2023 - 11:54 AM

@fox88

This is a very simple code optimization, but still very effective in terms of UI performance.

When having lots of files in download list with different categories switching category view takes lots of time and freezes UI. When I tested this and noticed that "HideFile(file)" takes a lot of time, while ShowFile(file) runs almost instant.
So using a "DeleteAllItems()" at start, then using only "ShowFile(file)" without "HideFile(file)" is a good solution and works almost instant. I tested this with 3000 small and paused files in download list with two different categories to make the problem more noticable, but probably less number of files will still show it.


<< Updated Code Delta Can Be Found In My Second Message >>

This post has been edited by BuyukBang: 03 September 2023 - 02:26 PM

1

#2 User is offline   fox88 

  • Golden eMule
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 4974
  • Joined: 13-May 07

Posted 20 May 2023 - 10:50 AM

Thanks, looks good. In other code parts DeleteAllItems was used similarly, but not here.
Unfortunately, the suggested code does not take into account possibility of displaying sources in the list of downloads.
Do not use this optimized code as it will intoroduce bugs.

This post has been edited by fox88: 21 August 2023 - 10:16 PM

0

#3 User is offline   BuyukBang 

  • Member
  • PipPip
  • Group: Members
  • Posts: 36
  • Joined: 04-May 23

Posted 03 September 2023 - 12:56 PM

You're right. I noticed this yesterday and visited here to wrote this and my second iteration for the solution.

Actually the root cause of the problem is the usage of "CDownloadListCtrl::ChangeCategory" for two different purpose in the eMule source code.
1- Changing category as the name suggest.
2- Updating Download List Control items to refresh the list.
IMHO the good solution is to split this into "CDownloadListCtrl::ChangeCategory" and something like "CDownloadListCtrl::RefreshDownloadList"
But since I'm trying to keep the code delta of my mod as minimum as possible, I changed the code as below. This solves above mentioned problem while keeping fast category optimization mentioned in my first message:


DownloadListCtrl.cpp
void CDownloadListCtrl::ChangeCategory(int newsel)
// BuyukBang <-- Optimization: Faster Category Switch
{
	SetRedraw(FALSE);

	// BuyukBang --> Optimization: Faster Category Switch
	if (curTab != newsel) {
		// remove all displayed files and show the files in the selected category
		DeleteAllItems();
		for (ListItems::const_iterator it = m_ListItems.begin(); it != m_ListItems.end(); ++it) {
			const CtrlItem_Struct* cur_item = it->second;
			if (cur_item->type == FILE_TYPE) {
				CPartFile* file = static_cast<CPartFile*>(cur_item->value);
				if (file->CheckShowItemInGivenCat(newsel))
					ShowFile(file);
			}
		}
	} else {
	// BuyukBang <-- Optimization: Faster Category Switch
		// remove all displayed files with a different cat and show the correct ones
		for (ListItems::const_iterator it = m_ListItems.begin(); it != m_ListItems.end(); ++it) {
			const CtrlItem_Struct* cur_item = it->second;
			if (cur_item->type == FILE_TYPE) {
				CPartFile* file = static_cast<CPartFile*>(cur_item->value);
				if (!file->CheckShowItemInGivenCat(newsel))
					HideFile(file);
				else
					ShowFile(file);
			}
		}
	} // BuyukBang <-- Optimization: Faster Category Switch

	SetRedraw(TRUE);
	curTab = newsel;
	ShowFilesCount();
}

This post has been edited by BuyukBang: 16 October 2023 - 09:50 AM

0

  • Member Options

Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users