Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit ffab1f5

Browse files
author
Paul Balaji
authored
Deployment Launcher editor performance improvement (#1219)
1 parent 8fc4663 commit ffab1f5

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
- A `WorkerSystem` now exposes the underlying Worker's `IsConnected` property. [#1217](https://github.com/spatialos/gdk-for-unity/pull/1217)
88

9+
### Fixed
10+
11+
- Fixed an issue where the Deployment Launcher window would feel unresponsive due to saving changes after every input. [#1219](https://github.com/spatialos/gdk-for-unity/pull/1219)
12+
- It will now wait for at least 1 second to elapse after the last change before writing the configuration back to disk.
13+
914
## `0.3.0` - 2019-11-11
1015

1116
### Breaking Changes

workers/unity/Packages/io.improbable.gdk.deploymentlauncher/DeploymentLauncherWindow.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ internal class DeploymentLauncherWindow : EditorWindow
3939
private List<DeploymentInfo> listedDeployments = new List<DeploymentInfo>();
4040
private int selectedListedDeploymentIndex;
4141

42+
// Minimum time required from last config change before saving to file
43+
private static readonly TimeSpan FileSavingInterval = TimeSpan.FromSeconds(1);
44+
private DateTime lastEditTime;
45+
4246
[MenuItem("SpatialOS/Deployment Launcher", false, 51)]
4347
private static void LaunchDeploymentMenu()
4448
{
@@ -57,8 +61,7 @@ private void OnEnable()
5761
if (launcherConfig != null && projectName != null)
5862
{
5963
launcherConfig.SetProjectName(projectName);
60-
EditorUtility.SetDirty(launcherConfig);
61-
AssetDatabase.SaveAssets();
64+
MarkConfigAsDirty();
6265
}
6366

6467
spinnerMaterial = new Material(Shader.Find("UI/Default"));
@@ -75,11 +78,15 @@ private void OnDestroy()
7578

7679
private void OnExit()
7780
{
81+
AssetDatabase.SaveAssets();
82+
7883
manager.Cancel();
7984
}
8085

8186
private void Update()
8287
{
88+
TrySaveChanges();
89+
8390
manager.Update();
8491

8592
foreach (var wrappedTask in manager.CompletedTasks.OfType<UploadTask>())
@@ -223,8 +230,7 @@ private void OnGUI()
223230
{
224231
projectName = GetProjectName();
225232
launcherConfig.SetProjectName(projectName);
226-
EditorUtility.SetDirty(launcherConfig);
227-
AssetDatabase.SaveAssets();
233+
MarkConfigAsDirty();
228234
}
229235
}
230236

@@ -307,8 +313,7 @@ private void OnGUI()
307313

308314
if (check.changed)
309315
{
310-
EditorUtility.SetDirty(launcherConfig);
311-
AssetDatabase.SaveAssets();
316+
MarkConfigAsDirty();
312317
}
313318

314319
if (manager.IsActive)
@@ -882,6 +887,23 @@ private string GetStatusMessage()
882887
return sb.ToString();
883888
}
884889

890+
private void MarkConfigAsDirty()
891+
{
892+
EditorUtility.SetDirty(launcherConfig);
893+
lastEditTime = DateTime.Now;
894+
}
895+
896+
private void TrySaveChanges()
897+
{
898+
var timeSinceLastEdit = DateTime.Now - lastEditTime;
899+
if (EditorUtility.GetDirtyCount(launcherConfig) <= 0 || timeSinceLastEdit <= FileSavingInterval)
900+
{
901+
return;
902+
}
903+
904+
AssetDatabase.SaveAssets();
905+
}
906+
885907
private bool IsSelectedValid<T>(List<T> list, int index)
886908
{
887909
return index >= 0 && index < list.Count;

0 commit comments

Comments
 (0)