]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java
Performance optimizations for NatTableGraphExplorer
[simantics/platform.git] / bundles / org.simantics.browsing.ui.nattable / src / org / simantics / browsing / ui / nattable / NatTableGraphExplorer.java
index be6a73a0c05dbff44a460e4b5de85bd9000947fb..9d12fd9b592f70e44bf842819cee245f2b596beb 100644 (file)
@@ -26,7 +26,6 @@ import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.resource.ColorDescriptor;
@@ -172,6 +171,7 @@ import org.simantics.browsing.ui.common.processors.DefaultViewpointProcessor;
 import org.simantics.browsing.ui.common.processors.IsExpandedProcessor;
 import org.simantics.browsing.ui.common.processors.NoSelectionRequestProcessor;
 import org.simantics.browsing.ui.common.processors.ProcessorLifecycle;
+import org.simantics.browsing.ui.common.state.ExplorerStates;
 import org.simantics.browsing.ui.content.Labeler;
 import org.simantics.browsing.ui.content.Labeler.CustomModifier;
 import org.simantics.browsing.ui.content.Labeler.DialogModifier;
@@ -198,6 +198,7 @@ import org.simantics.utils.threads.SWTThread;
 import org.simantics.utils.threads.ThreadUtils;
 import org.simantics.utils.ui.AdaptionUtils;
 import org.simantics.utils.ui.ISelectionUtils;
+import org.simantics.utils.ui.SWTUtils;
 import org.simantics.utils.ui.jface.BasePostSelectionProvider;
 
 import gnu.trove.map.hash.THashMap;
@@ -580,17 +581,16 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
     private void initializeState() {
         if (persistor == null)
             return;
+        ExplorerStates.scheduleRead(getRoot(), persistor)
+        .thenAccept(state -> SWTUtils.asyncExec(natTable, () -> restoreState(state)));
+    }
 
-        ExplorerState state = persistor.deserialize(
-                Platform.getStateLocation(Activator.getDefault().getBundle()).toFile(),
-                getRoot());
-
-
+    private void restoreState(ExplorerState state) {
         Object processor = getPrimitiveProcessor(BuiltinKeys.IS_EXPANDED);
         if (processor instanceof DefaultIsExpandedProcessor) {
             DefaultIsExpandedProcessor isExpandedProcessor = (DefaultIsExpandedProcessor)processor;
             for(NodeContext expanded : state.expandedNodes) {
-                isExpandedProcessor.setExpanded(expanded, true);
+                isExpandedProcessor.replaceExpanded(expanded, true);
             }
         }
     }
@@ -993,11 +993,15 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
        //       we have to remove all references here to reduce memory consumption.
        //      
        //       Proper fix would be to remove references between QueryCache and GENodeQueryManagers.
+       
+       // Clearing explorerContext replaces GECache with dummy implementation, which makes node disposal much faster.
+       explorerContext.close();
        if (rootNode != null) {
-               rootNode.dispose();
+               // Using fastDispose bypasses item removal from nodeMap, which is cleared later. 
+               rootNode.fastDispose();
                rootNode = null;        
         }      
-        explorerContext.dispose();
+       explorerContext.dispose();
         explorerContext = null;
         processors.clear();
         detachPrimitiveProcessors();
@@ -1026,8 +1030,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
         }
         resourceManager.dispose();
         resourceManager = null;
-                       
-        contextToNodeMap.clear(); // should be empty at this point.
+        contextToNodeMap.clear();      
         contextToNodeMap = null;
         if (postSelectionProvider != null) {
                postSelectionProvider.dispose();
@@ -2394,6 +2397,13 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
             }
         };
         
+        public void close() {
+               cache.dispose();
+               cache = new DummyCache();
+               scheduleList.clear();
+               autoExpanded.clear();
+        }
+        
         @Override
         public void dispose() {
                cache.dispose();
@@ -2605,6 +2615,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
                final HashMap<GECacheKey, IGECacheEntry> entries = new HashMap<GECacheKey, IGECacheEntry>();
                final HashMap<GECacheKey, Set<UIElementReference>> treeReferences = new HashMap<GECacheKey, Set<UIElementReference>>();
                final HashMap<NodeContext, Set<GECacheKey>> keyRefs = new HashMap<NodeContext, Set<GECacheKey>>();
+               private TObjectIntHashMap<NodeContext> references = new TObjectIntHashMap<NodeContext>();
                
                 /**
             * This single instance is used for all get operations from the cache. This
@@ -2731,7 +2742,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
                return references.get(context) > 0;
            }
 
-           private TObjectIntHashMap<NodeContext> references = new TObjectIntHashMap<NodeContext>();
+           
            
            @Override
            public void incRef(NodeContext context) {