]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Prime SCL BindingRegistry to shave ~0.5s from startup 72/3972/2
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 6 Mar 2020 11:47:01 +0000 (13:47 +0200)
committerJani Simomaa <jani.simomaa@semantum.fi>
Fri, 6 Mar 2020 11:47:28 +0000 (11:47 +0000)
gitlab #491

Change-Id: Ibbb04dce327697b81fdce894e10569af6b62c309

bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/Activator.java
bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/registry/BindingRegistry.java
bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/registry/Namespace.java

index 4e1d01816381d3ca486bae5b558f07f9af5cb7b2..a14be489618d659c6bf394405bce1e2d8868ac04 100644 (file)
@@ -1,11 +1,14 @@
 package org.simantics.scl.reflection.internal;
 
+import java.util.concurrent.ForkJoinPool;
+
 import org.eclipse.core.runtime.ILog;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
+import org.simantics.scl.reflection.internal.registry.BindingRegistry;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -20,6 +23,21 @@ public class Activator implements BundleActivator {
     public void start(BundleContext context) throws Exception {
         this.context = context;
         instance = this;
+        
+        primeBindingRegistry();
+    }
+
+    private static void primeBindingRegistry() {
+        LOGGER.info("Priming BindingRegistry");
+        ForkJoinPool.commonPool().submit(() -> {
+            try {
+                // this forces static initialzation of the registry in advance
+                BindingRegistry.primeBindingRegistry();
+            } catch (Exception e) {
+                LOGGER.error("Could not prime binding registry", e);
+            }
+            LOGGER.info("Priming done");
+        });
     }
 
     @Override
index f9bf3fadcc9aa3bfa47155909949d136dfe3796a..648e314d9a2f95c9dc659615514f0133c1efbf64 100644 (file)
@@ -49,6 +49,12 @@ public class BindingRegistry {
         }
     }
     
+    public static void primeBindingRegistry() {
+        for (Namespace ns : namespaces.values()) {
+            ns.initializeValues();
+        }
+    }
+    
     static {
         initialize();
         if (DEBUG_INIT) {
index daaa204dbe708c971969ba65a3ef68bb73390651..5234d3bfc95ab456f61ceff4c5e06e134ddeaab7 100644 (file)
@@ -275,7 +275,7 @@ public class Namespace {
         }
     }        
         
-    private synchronized void initializeValues() {
+    synchronized void initializeValues() {
         if(values == null) {
             initializeTypes();
             TypeBindingScheme scheme = MinimalTypeBindingScheme.INSTANCE;