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

Drawing number of objects on sockets #2772

Closed
Durman opened this issue Dec 27, 2019 · 9 comments
Closed

Drawing number of objects on sockets #2772

Durman opened this issue Dec 27, 2019 · 9 comments

Comments

@Durman
Copy link
Collaborator

Durman commented Dec 27, 2019

Problem statement

The function is calling each time when UI is redrawing. UI is redrawing each time when mouse is passed over any interactive element on a screen. The function is calling other method of socket which is calling links method which is actually quite expensive. Calling links method takes O(n) time where n is number of links in a tree.

def SvGetSocketInfo(socket):
"""returns string to show in socket label"""
global socket_data_cache
ng = socket.id_data.name
if socket.is_output:
s_id = socket.socket_id
elif socket.is_linked:
other = socket.other
if other:
s_id = other.socket_id
else:
return ''
else:
return ''
if ng in socket_data_cache:
if s_id in socket_data_cache[ng]:
data = socket_data_cache[ng][s_id]
if data:
return str(len(data))
return ''

So with growing size of a tree number of calculations is growing exponentially and recalculating quite often. It definitely can be reimplemented. I think that number of objects can be recalculated during tree update event and memorize in sockets somewhere.

@zeffii
Copy link
Collaborator

zeffii commented Dec 27, 2019

perhaps, the socket class common can hold a 'object count', which is set only at the end of a successful completion of a node's process() (also means setting to a default 0 prior to calling process ).

i've thought about this too in the past when visiting these areas of code, and i'm supportive of reducing redundant cpu cycles, but here i'm apprehensive to implement object count.

@zeffii
Copy link
Collaborator

zeffii commented Dec 27, 2019

but whatever :) we can try it

@ly29
Copy link
Collaborator

ly29 commented Dec 29, 2019

Having a compiled links data structure would be good and would also make the update system easier.
Removing reroutes and wifi (if that is still is used) is a big win and would make the update system easier.

@ly29
Copy link
Collaborator

ly29 commented Dec 29, 2019

Made a very simple cache implementation for these kind of issues. Untested as a minimal implemenation.
https://github.com/nortikin/sverchok/blob/testNameCache/core/socket_data.py

@Durman
Copy link
Collaborator Author

Durman commented Jan 6, 2020

By the way I was thinking about socket.sv_links approach and it looks it would be impossible to implement. Because what this method should returns? We can't keep straight references to nodes. Links to nodes can't be created via Pointer property. We can keep their names but search node by their name again returns to O(n**2) performance.

Or probably it would be possible to keep references to nodes but they will resetting upon each update event and undo event. In this case it becomes easier to crush Blender.

@nortikin
Copy link
Owner

nortikin commented Feb 3, 2020

default off
optionally turn it on from SvPanel and options also.
It was initially as replacement for text viewer before it appeared.

I will not miss personally.
Point before socket name when it joined - good approach

@Durman
Copy link
Collaborator Author

Durman commented May 21, 2020

lags

info_text = t + '. ' + SvGetSocketInfo(self)

And performance without calling the function.

info_text = t + '. ' 

no lags

@Durman Durman added the todo label May 21, 2020
@nortikin
Copy link
Owner

every time calculate length is much of lost?

@Durman Durman mentioned this issue Sep 2, 2020
4 tasks
@Durman
Copy link
Collaborator Author

Durman commented Sep 6, 2020

According the fact that not just number of objects of other output sockets should be shown but also the number of objects after they will be converted from that sockets the only way to improve performance is to calculate and to memorize this value during update event. Only case when number of objects does not coincide is conversion from vector to matrix sockets now. And the reason of it is that matrixes are treated differently and inconsistently with other data types.

@Durman Durman closed this as completed Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants