Permalink
Browse files

Don't install profiler prefs multiple times or when an appropriate pr…

…ofiler exists already

In a couple cases the profiler preferences file was being written to twice when it should have been written to zero or one time. When compiling a file with a dozen procs in it, this would write to the profiler preferences file at least two dozen times. On a test server this previously accounted for 60% of total compile time. After this fix, generating a standalone environment now only accounts for 21% in the same test.
  • Loading branch information...
PseudoKnight committed Oct 10, 2017
1 parent 15e4836 commit c68ed4b109c8b0b722bed7afe206c7e36693bbd7
@@ -1788,7 +1788,7 @@ private static void optimize(ParseTree tree, Stack<List<Procedure>> procs, Set<C
Script fakeScript = Script.GenerateScript(root, "*");
Environment env = null;
try {
env = Static.GenerateStandaloneEnvironment();
env = Static.GenerateStandaloneEnvironment(false);
} catch (IOException | DataSourceException | URISyntaxException | Profiles.InvalidProfileException e) {
//
}
@@ -5,6 +5,7 @@
import com.laytonsmith.PureUtilities.SimpleVersion;
import com.laytonsmith.PureUtilities.TermColors;
import com.laytonsmith.PureUtilities.XMLDocument;
import com.laytonsmith.abstraction.Implementation;
import com.laytonsmith.abstraction.MCCommandSender;
import com.laytonsmith.abstraction.MCConsoleCommandSender;
import com.laytonsmith.abstraction.MCEntity;
@@ -1251,20 +1252,32 @@ public static void AssertNonNull(Object var, String message) throws NullPointerE
* @throws DataSourceException
* @throws URISyntaxException
*/
public static Environment GenerateStandaloneEnvironment() throws IOException, DataSourceException, URISyntaxException, Profiles.InvalidProfileException {
public static Environment GenerateStandaloneEnvironment(boolean install) throws IOException, DataSourceException, URISyntaxException, Profiles.InvalidProfileException {
File platformFolder = MethodScriptFileLocations.getDefault().getConfigDirectory();
Installer.Install(platformFolder);
if(install) {
Installer.Install(platformFolder);
}
ConnectionMixinFactory.ConnectionMixinOptions options = new ConnectionMixinFactory.ConnectionMixinOptions();
options.setWorkingDirectory(platformFolder);
PersistenceNetwork persistenceNetwork = new PersistenceNetwork(MethodScriptFileLocations.getDefault().getPersistenceConfig(),
new URI("sqlite://" + new File(platformFolder, "persistence.db").getCanonicalPath().replace('\\', '/')), options);
Profiler profiler;
if(Implementation.GetServerType().equals(Implementation.Type.BUKKIT) && CommandHelperPlugin.self.profiler != null) {
profiler = CommandHelperPlugin.self.profiler;
} else {
profiler = new Profiler(MethodScriptFileLocations.getDefault().getProfilerConfigFile());
}
GlobalEnv gEnv = new GlobalEnv(new MethodScriptExecutionQueue("MethodScriptExecutionQueue", "default"),
new Profiler(MethodScriptFileLocations.getDefault().getProfilerConfigFile()), persistenceNetwork, platformFolder,
profiler, persistenceNetwork, platformFolder,
new Profiles(MethodScriptFileLocations.getDefault().getProfilesFile()), new TaskManager());
gEnv.SetLabel(GLOBAL_PERMISSION);
return Environment.createEnvironment(gEnv, new CommandHelperEnvironment());
}
public static Environment GenerateStandaloneEnvironment() throws IOException, DataSourceException, URISyntaxException, Profiles.InvalidProfileException {
return GenerateStandaloneEnvironment(true);
}
/**
* Asserts that all the args are not CNulls. If so, throws a
* ConfigRuntimeNullPointerException
@@ -1,6 +1,5 @@
package com.laytonsmith.tools;
import com.laytonsmith.PureUtilities.Common.ArrayUtils;
import com.laytonsmith.PureUtilities.Common.FileUtil;
import com.laytonsmith.PureUtilities.Common.MutableObject;
import com.laytonsmith.PureUtilities.Common.StreamUtils;
@@ -451,7 +450,7 @@ private void doStartup() throws IOException, DataSourceException, URISyntaxExcep
Installer.Install(MethodScriptFileLocations.getDefault().getConfigDirectory());
Installer.InstallCmdlineInterpreter();
env = Static.GenerateStandaloneEnvironment();
env = Static.GenerateStandaloneEnvironment(false);
env.getEnv(GlobalEnv.class).SetCustom("cmdline", true);
if (Prefs.UseColors()) {
TermColors.EnableColors();

0 comments on commit c68ed4b

Please sign in to comment.