Skip to content

Commit

Permalink
Don't install profiler prefs multiple times or when an appropriate pr…
Browse files Browse the repository at this point in the history
…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 c68ed4b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
//
}
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/com/laytonsmith/core/Static.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/laytonsmith/tools/Interpreter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c68ed4b

Please sign in to comment.