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

V3 indexation #1378

Closed
wants to merge 7 commits into from
Closed

V3 indexation #1378

wants to merge 7 commits into from

Conversation

sim51
Copy link
Collaborator

@sim51 sim51 commented Sep 18, 2023

See #1372

See issue #1290 and its comments.

If there is no draggedEvents, we don't need to call the refresh.
Tested with it `hideEdgesOnMove`, and the behavior is good.
Moreover it avoid a render on a simple click.
- reducers are only call when the node/Edge data changed (not at every hard render)
- listeners on graphology event do the cache data indexation
@sim51 sim51 requested a review from jacomyal September 18, 2023 15:12
@jacomyal
Copy link
Owner

jacomyal commented Sep 18, 2023

  • Methods are named with the verb at the end (e.g., nodeAdd), while all other method names start with verbs
  • Private methods added to the codebase are placed after the public methods, whereas they were well grouped before
  • Bug: In the mouse-manipulations example, when moving a node with the mouse, it permanently becomes hovered
  • The management of itemsWithForcedLabels with arrays is a bit concerning, given the new modifications, and might perhaps be better replaced with Set<string>:
    • this.nodesWithForcedLabels = this.nodesWithForcedLabels.filter((e) => e !== key); doesn't scale well
    • this.nodesWithForcedLabels.includes(key) also doesn't scale well
  • Right now, the getNodeDisplayData and getEdgeDisplayData methods expose the programIndex data, which shouldn't be exposed
  • The naming rePaint introduces new complexity, while the current public API only has two concepts: render is about "only painting", while refresh is about indexing and then painting. So, here are my suggestions:
    • refresh now can accept optional { partialGraph?: { nodes?: string[], edges?: string[] } }. If it receives at least one of those, it should run current rePaint code instead, but without scheduling
    • Also, refresh can take a new optional { schedule?: boolean } argument, in which case it schedules the call to render instead
    • In addition, scheduleRefresh({ partialGraph?: { nodes?: string[], edges?: string[] } }) becomes an alias to refresh({ partialGraph?: { nodes?: string[], edges?: string[] }, schedule: true })
    • Finally, this refresh method would accept another optional boolean argument layoutUnchanged?: boolean, that would be used to decide whether to re-index the graph spatially or not

@Yomguithereal We would like your feedback with @sim51 on those suggestions, especially on everything related to public APIs.

Function refresh can updates all dataCache, update the programs data and call a render if a partial graph is provided.
It bypass all actions related to nodes coordinates (like quadtree, labelGrid) if layoutUnchanged is at true..
Moreover, you can also specify if it should do a render or schedule it.
// Compute the partial that we need to re-render
// to optimized the refresh
const partialGraph = { nodes: [], edges: [] };
partialGraph.nodes = graph.nodes().filter((n) => n !== state.hoveredNode && !state.hoveredNeighbors.has(n));
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should use graph.filterNodes and graph.filterEdges for better performance.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The next part uses a O(n) lookup in the nodes array but I guess the likelihood of it being the problem at hover level is quite low since the number of relevant nodes will be low? But why not asking the question to the graph itself? Like performing the union of edges incident to the hovered nodes or something of the kind?

"@babel/core": "^7.16.5",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"@babel/core": "^7.22.17",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we merge the package updates separately?

array.length += l2;

let i = 0;
for (const value of values) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have not benchmarked this kind of stuff lately but usually using Set.forEach is faster than for of.

const updatedFields = e.hints?.attributes;
// we process all nodes
const nodes = this.graph.nodes();
nodes.forEach((node) => this.updateNode(node));
Copy link
Collaborator

Choose a reason for hiding this comment

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

graph.forEachNode will be faster.

this.activeListeners.graphUpdate = () => {
this.scheduleRefresh();
this.activeListeners.eachNodeAttributesUpdatedGraphUpdate = (e: { hints?: { attributes?: string[] } }) => {
const updatedFields = e.hints?.attributes;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Those hints are completely optional. I guess we need to consider everything might have changed if the hint was not provided to avoid frustration? It might be what the current code does.

@Yomguithereal
Copy link
Collaborator

I did not read everything thoroughly but can this enable us getting rid of the weird internal refresh/_refresh thingy or was it already fixed? Also, the API seems good. We will be able to optimize further later by minimizing the number of lookups overall I think.

jacomyal added a commit that referenced this pull request Oct 4, 2023
@jacomyal jacomyal closed this Oct 4, 2023
@jacomyal jacomyal deleted the v3-indexation branch October 4, 2023 13:14
@jacomyal
Copy link
Owner

jacomyal commented Oct 4, 2023

(I manually merged this PR)

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.

3 participants