cylynx / motif.gl

Open source, no-code, network visualization tool for graph analysis and investigation
https://demo.cylynx.io
MIT License
123 stars 12 forks source link

Enhancement - Performance Optimisation - Toggle Visibility #181

Closed CodesAreHonest closed 3 years ago

CodesAreHonest commented 3 years ago

Root Cause

Screenshot 2021-07-13 at 4 55 39 PM

1.combineProcessedData perform removeDuplicates on every single graphList with significant growth rates on according to data size... results in huge consumption in JSHeap.

  1. dispatch is expensive due to the nature of immutability, results in huge execution time on data processing.
  2. Every single toggle requires to perform loops repeatedly on all the graph list.
Set graphFlatten to [];
For graphData in graphList

 If graphData.metadata.visible = true
    Call groupEdgeForImportation with graphData and groupEdgeField return groupEdgeGraph
        duplicateDictionary 
        obtainGroupEdgeIds 
        aggregateGroupEdges 
        produceGraphWithGroupEdges 
        aggregateMetadataFields
        combineEdgeFields
    Set graphData = groupEdgeGraph
 Endif

 // O(nodes + edges + nodeFields+ edgeFields)
 Call combinedProcessData
        removeDuplicates 
Endfor

Solutions

Turn Graph List Visibility Off

  1. To prevent the feature requires to perform looping and merging on every graph list. With the metadata.ids and metadata.groupEdge.fields setup in #179 , we will use the nodeIds, edgeIds and groupEdgeIds to perform removal from the graphFlatten.
  2. This operation reduce the time complexity from O(n*3) to O(n).
function disableGraphVisibility (index, isVisible)

    // obtain stores data
    Set graphList to state.graphList;
    Set graphFlatten to state.graphFlatten;

    // modify visibility and obtain specific graph
    Set graphList[index].visible = isVisible;
    Set graphData to graphList[index];

    Set nodeIdsForRemoval to graphData.metadata.ids.node
    Set edgeIdsForRemoval to graphData.metadata.ids.edge and graphData.metadata.groupEdge.fields.key

    // Remove all nodes and edges of specific graph
    Call graphFlatten.graphNodeEntity.removeAll(nodeIdsForRemoval)
    Call graphFlatten.graphEdgeEntity.removeAll(edgeIdsForRemoval)

    Set state.graphFlatten = graphFlatten

end function

Turn Graph List Visibility On

  1. To prevent the feature requires to perform looping and merging on every graph list. With the metadata.ids and metadata.groupEdge.fields setup in #179 , we will use the nodeIds, edgeIds and groupEdgeIds to perform insertion into the graphFlatten.
  2. This operation reduce the time complexity from O(n^3) to O(n^2).
function enableGraphVisiblity (index, isVisible)

    // obtain stores data
    Set graphList to state.graphList;
    Set graphFlatten to state.graphFlatten;

    // modify visibility and obtain specific graph
    Set graphList[index].visible = isVisible;
    Set graphData to graphList[index];

    Set modData = graphData
    if graphData.metadata.groupEdge.toggle = true
        Call groupEdgeForImportation with graphData return groupEdgeData and groupEdgeIds;
        Set modData = groupEdgeData; 
        Set modData.metadata.groupEdge.ids = groupEdgeIds;
    endif

    Call combinedProcessedData(modData, graphFlatten) return mergedGraph;
    Set state.graphFlatten = mergedGraph

end function
CodesAreHonest commented 3 years ago

As #184 is not implemented, we will refactor combinedProcessedData out from the loops with the reason stated in comments