Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speed up sortEventListenersOfSceneGraphPriority by reverse visit #19849

Open
wants to merge 9 commits into
base: v3
Choose a base branch
from

Conversation

huangwei1024
Copy link

speed up sortEventListenersOfSceneGraphPriority by reverse visit
its more efficient when node tree was big

{
Node* node = l->getAssociatedNode();
if (node)
node->setUserData((void*)1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can not setUserData.
It can be used by user.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I known its not a right way which use UserData to storage some visit information for engine. and its simple to add an "SystemData" in Node for optimize

@@ -222,6 +222,83 @@ EventDispatcher::~EventDispatcher()
removeAllEventListeners();
}


void EventDispatcher::visitTree(Node* node)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain new algorithm and provide profile results. What is the speedup.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (; i < childrenCount; i++)
{
	child = children.at(i);
	if (child && child->getLocalZOrder() < 0)
	{
		if (child->getUserData() == 0) // here!!!
			continue;
		visitTree(child);
	}
	else
		break;
}

I think its easy idea, if the tree had N nodes, and the sceneGraphListeners had M listeners, you could visit from M listener node to root, and color the path.
second, visit from root to child by the colored path. it could be avoid to visit useless path.

in my test proj, I had tree which contain 6K nodes, but listeners only about 600. I thought the case which listnener much less than nodes was in general. O(N) -> O(cM), c is the coefficient about the avg children and node in path. but in the worst cM = N

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I could not provide the test case, it contain too many complex widgets.
but I test in win32, the old method cost 8ms, and cost 3ms when use the new one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

		if ((nodeData & 1) == 1)
			_globalZOrderNodeMap[node->getGlobalZOrder()].push_back(node);
if (_nodeListenersMap.find(node) != _nodeListenersMap.end())
        {
            _globalZOrderNodeMap[node->getGlobalZOrder()].push_back(node);
        }

and stl unordered_map also more expensive than bit mask.
when the N nodes is big, the cost need be consider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants