From 8f99af83cee60676d80cf2334177ab94f82b7959 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Fri, 6 Mar 2020 13:47:01 +0200 Subject: [PATCH] Prime SCL BindingRegistry to shave ~0.5s from startup gitlab #491 Change-Id: Ibbb04dce327697b81fdce894e10569af6b62c309 --- .../scl/reflection/internal/Activator.java | 18 ++++++++++++++++++ .../internal/registry/BindingRegistry.java | 6 ++++++ .../internal/registry/Namespace.java | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/Activator.java b/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/Activator.java index 4e1d01816..a14be4896 100644 --- a/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/Activator.java +++ b/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/Activator.java @@ -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 diff --git a/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/registry/BindingRegistry.java b/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/registry/BindingRegistry.java index f9bf3fadc..648e314d9 100644 --- a/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/registry/BindingRegistry.java +++ b/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/registry/BindingRegistry.java @@ -49,6 +49,12 @@ public class BindingRegistry { } } + public static void primeBindingRegistry() { + for (Namespace ns : namespaces.values()) { + ns.initializeValues(); + } + } + static { initialize(); if (DEBUG_INIT) { diff --git a/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/registry/Namespace.java b/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/registry/Namespace.java index daaa204db..5234d3bfc 100644 --- a/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/registry/Namespace.java +++ b/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/registry/Namespace.java @@ -275,7 +275,7 @@ public class Namespace { } } - private synchronized void initializeValues() { + synchronized void initializeValues() { if(values == null) { initializeTypes(); TypeBindingScheme scheme = MinimalTypeBindingScheme.INSTANCE; -- 2.47.1