Print Page | Close Window

Performance problem when deleting items from grid

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Property Grid
Forum Description: Topics Related to Codejock Property Grid
URL: http://forum.codejock.com/forum_posts.asp?TID=9211
Printed Date: 27 November 2024 at 2:05am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Performance problem when deleting items from grid
Posted By: farr02
Subject: Performance problem when deleting items from grid
Date Posted: 03 January 2008 at 4:00am
Hello,
in my application I noticed a performance problem when deleting a large number of elements from the grid via pItem->Remove();
Example:
First I create a large number of categories each holds two items:
CString sCatName;
g_pCustom = m_wndPropertyGrid.AddCategory(_T("Long Dialog"));
for(int i = 0; i < 512; ++i)
{
    sCatName.Format(_T("Category %03d"), i);
    CXTPPropertyGridItem* pCat =
        g_pCustom->AddChildItem(new CXTPPropertyGridItemCategory(sCatName));
    pCat->AddChildItem(new CXTPPropertyGridItemNumber(_T("Element 1"), i));
    pCat->AddChildItem(new CXTPPropertyGridItemNumber(_T("Element 2"), i));
    pCat->Expand();
}
g_pCustom->Expand();


Then I delete 'Element 1' in every category using the following code:
if(g_pCustom)
{
    CXTPPropertyGridItems* pItems = g_pCustom->GetChilds();
    if(pItems)
    {
        int i = pItems->GetCount() - 1;
        while (i >= 0)
        {
            CXTPPropertyGridItem* pCategory = pItems->GetAt(i);
            if(pCategory)
            {
                CXTPPropertyGridItems* pElements = pCategory->GetChilds();
                if(pElements)
                {
                    CXTPPropertyGridItem* pElement1 = pElements->GetAt(0);
                    if(pElement1)
                    {
                        // here 'Element 1' will be deleted
                        pElement1->Remove();
                        pElement1 = 0;
                    }
                }
            }
            --i;
        }
    }
}

The removal of the elements takes more than a minute in release configuration on a 3 GHz computer running Win XP and ToolkitPro v9.81, whereas creation time is less than a second.
Is something wrong with my code or takes the remove-function so much time?
(I think the problem may be the call to m_pGrid->Refresh(); in the remove function.)
How can I speed up the removal?

Bye
   Holger




Replies:
Posted By: Oleg
Date Posted: 03 January 2008 at 6:57am
Hi,
 
There are BeginUpdate, EndUpdate methods.
call them before/after your loop.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: farr02
Date Posted: 03 January 2008 at 10:41am
Hello Oleg,

I have already made some testing with Begin/EndUpdate before. When I just put them around the while-loop in the above code, the result is an empty grid. As far as I understood (please correct me if I am wrong) BeginUpdate stores some information about some grid states, disables refresh and redraw and finally deletes the whole grid. EndUpdate restores the saved states,  enables refresh and redraw and then redraws the grid. That means I have to rebuild my whole dialog inside a Begin/EndUpdate-block instead of just inserting or deleting a number of items into resp. from the existing dialog.

Maybe this is an item for the wish-list:
Implement a function that locks grid refreshing and redrawing during a bunch of insertion or removal operations without the need to rebuild the whole dialog.

Bye
   Holger

PS: I have forgotten in my first post: Happy New Year!


Posted By: Oleg
Date Posted: 03 January 2008 at 11:18am
oh, right, it deletes content.
 
ok, try this
 
 wndGrid.GetGridView().m_nLockUpdate = 1;
 wndGrid.GetGridView().SetRedraw(FALSE);
 
 wndGrid.GetGridView().m_nLockUpdate = 0;
 wndGrid.GetGridView().SetRedraw(FALSE);
 


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: farr02
Date Posted: 04 January 2008 at 6:21am
Hi Oleg,
doesn't work
It leads to an access violation in CXTPPropertyGridView::_RefreshIndexes(). I have tried to eliminate the call to Refresh in the CXTPPropertyGridItem::Remove function but that gives me other errors.
So I think for the moment it is the best to stay with the current situation and hope for one of the next releases. Or do you have a better idea?

Thank you yery much.
Bye
   Holger


Posted By: Oleg
Date Posted: 04 January 2008 at 8:36am
Hi,
Think also you  need call Refresh() in the end.  (after SetRedraw(FALSE))


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: farr02
Date Posted: 07 January 2008 at 4:50am
Hello Oleg,

doesn't work either:-(
I uploaded two files regarding the access violation: Number one ( uploads/20080107_042735_CJ_Fhut.zip - uploads/20080107_042735_CJ_Fhut.zip ) is a crash dump file saved with WinDbg (WinDbg command: .dump /mFhut CJ_Fhut.dmp) and the second (  uploads/20080107_043556_ProblemItemRemo.zip - uploads/20080107_043556_ProblemItemRemo.zip )gives you a small description of the functions I inserted to the lib, and some more information about the access violation.

Hope it helps.
Bye
   Holger




Posted By: Oleg
Date Posted: 08 January 2008 at 2:03am
Hi,
Last version to try: :)
 
void BeginUpdate()
{
    GetGridView().m_nLockUpdate = 1;
    GetGridView().SetRedraw(FALSE);
    GetGridView().().ResetContent();
}
void EndUpdate()
{
    GetGridView().m_nLockUpdate = 0;
    GetGridView().SetRedraw(TRUE);
    Refresh();
}
 
Think it will work fine.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: farr02
Date Posted: 08 January 2008 at 10:19am
Hi Oleg,

your are right: The code works fine.
Thank you very much.

Bye
   Holger




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net