Optimize content modifications watching events processing in large projects
This commit is contained in:
@@ -24,7 +24,7 @@ namespace FlaxEditor.Modules
|
|||||||
private bool _rebuildInitFlag;
|
private bool _rebuildInitFlag;
|
||||||
private int _itemsCreated;
|
private int _itemsCreated;
|
||||||
private int _itemsDeleted;
|
private int _itemsDeleted;
|
||||||
private readonly HashSet<MainContentFolderTreeNode> _dirtyNodes = new HashSet<MainContentFolderTreeNode>();
|
private readonly HashSet<ContentFolderTreeNode> _dirtyNodes = new HashSet<ContentFolderTreeNode>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The project directory.
|
/// The project directory.
|
||||||
@@ -1309,26 +1309,31 @@ namespace FlaxEditor.Modules
|
|||||||
|
|
||||||
internal void OnDirectoryEvent(MainContentFolderTreeNode node, FileSystemEventArgs e)
|
internal void OnDirectoryEvent(MainContentFolderTreeNode node, FileSystemEventArgs e)
|
||||||
{
|
{
|
||||||
// Ensure to be ready for external events
|
// Ignore events during fast setup
|
||||||
if (_isDuringFastSetup)
|
if (_isDuringFastSetup)
|
||||||
return;
|
return;
|
||||||
|
ContentFolderTreeNode dirtyNode = node;
|
||||||
|
|
||||||
// TODO: maybe we could make it faster! since we have a path so it would be easy to just create or delete given file. but remember about subdirectories
|
// Filter the node based on modified path
|
||||||
|
// (eg. if we have event for 'Content/Folder1/Folder2' and node is 'Content/Folder1' then we should process but skip other 'Content' subfolders)
|
||||||
|
var path = StringUtils.NormalizePath(Path.GetDirectoryName(e.FullPath));
|
||||||
|
var pathItem = node.Folder.Find(path) as ContentFolder;
|
||||||
|
if (pathItem != null)
|
||||||
|
{
|
||||||
|
dirtyNode = pathItem.Node;
|
||||||
|
}
|
||||||
|
|
||||||
// Switch type
|
|
||||||
switch (e.ChangeType)
|
switch (e.ChangeType)
|
||||||
{
|
{
|
||||||
case WatcherChangeTypes.Created:
|
case WatcherChangeTypes.Created:
|
||||||
case WatcherChangeTypes.Deleted:
|
case WatcherChangeTypes.Deleted:
|
||||||
case WatcherChangeTypes.Renamed:
|
case WatcherChangeTypes.Renamed:
|
||||||
{
|
|
||||||
lock (_dirtyNodes)
|
lock (_dirtyNodes)
|
||||||
{
|
{
|
||||||
_dirtyNodes.Add(node);
|
_dirtyNodes.Add(dirtyNode);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnScriptsReload()
|
private void OnScriptsReload()
|
||||||
@@ -1383,14 +1388,15 @@ namespace FlaxEditor.Modules
|
|||||||
// Update all dirty content tree nodes
|
// Update all dirty content tree nodes
|
||||||
lock (_dirtyNodes)
|
lock (_dirtyNodes)
|
||||||
{
|
{
|
||||||
|
Profiler.BeginEvent("ContentDatabase.Refresh");
|
||||||
foreach (var node in _dirtyNodes)
|
foreach (var node in _dirtyNodes)
|
||||||
{
|
{
|
||||||
LoadFolder(node, true);
|
LoadFolder(node, true);
|
||||||
|
|
||||||
if (_enableEvents)
|
|
||||||
WorkspaceModified?.Invoke();
|
|
||||||
}
|
}
|
||||||
|
if (_enableEvents && _dirtyNodes.Count != 0)
|
||||||
|
WorkspaceModified?.Invoke();
|
||||||
_dirtyNodes.Clear();
|
_dirtyNodes.Clear();
|
||||||
|
Profiler.EndEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lazy-rebuilds
|
// Lazy-rebuilds
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ CreateAssetContext::CreateAssetContext(const StringView& inputPath, const String
|
|||||||
|
|
||||||
CreateAssetResult CreateAssetContext::Run(const CreateAssetFunction& callback)
|
CreateAssetResult CreateAssetContext::Run(const CreateAssetFunction& callback)
|
||||||
{
|
{
|
||||||
|
PROFILE_CPU();
|
||||||
|
PROFILE_MEM(Content);
|
||||||
ASSERT(callback.IsBinded());
|
ASSERT(callback.IsBinded());
|
||||||
|
|
||||||
// Call action
|
// Call action
|
||||||
@@ -207,6 +209,9 @@ void CreateAssetContext::AddMeta(JsonWriter& writer) const
|
|||||||
|
|
||||||
void CreateAssetContext::ApplyChanges()
|
void CreateAssetContext::ApplyChanges()
|
||||||
{
|
{
|
||||||
|
PROFILE_CPU();
|
||||||
|
PROFILE_MEM(Content);
|
||||||
|
|
||||||
// Get access
|
// Get access
|
||||||
auto storage = ContentStorageManager::TryGetStorage(TargetAssetPath);
|
auto storage = ContentStorageManager::TryGetStorage(TargetAssetPath);
|
||||||
if (storage && storage->IsLoaded())
|
if (storage && storage->IsLoaded())
|
||||||
@@ -274,6 +279,8 @@ bool AssetsImportingManager::Create(const String& tag, const StringView& outputP
|
|||||||
|
|
||||||
bool AssetsImportingManager::Import(const StringView& inputPath, const StringView& outputPath, Guid& assetId, void* arg)
|
bool AssetsImportingManager::Import(const StringView& inputPath, const StringView& outputPath, Guid& assetId, void* arg)
|
||||||
{
|
{
|
||||||
|
PROFILE_CPU();
|
||||||
|
PROFILE_MEM(Content);
|
||||||
LOG(Info, "Importing file '{0}' to '{1}'...", inputPath, outputPath);
|
LOG(Info, "Importing file '{0}' to '{1}'...", inputPath, outputPath);
|
||||||
|
|
||||||
// Check if input file exists
|
// Check if input file exists
|
||||||
@@ -347,6 +354,7 @@ String AssetsImportingManager::GetImportPath(const String& path)
|
|||||||
bool AssetsImportingManager::Create(const Function<CreateAssetResult(CreateAssetContext&)>& callback, const StringView& inputPath, const StringView& outputPath, Guid& assetId, void* arg)
|
bool AssetsImportingManager::Create(const Function<CreateAssetResult(CreateAssetContext&)>& callback, const StringView& inputPath, const StringView& outputPath, Guid& assetId, void* arg)
|
||||||
{
|
{
|
||||||
PROFILE_CPU();
|
PROFILE_CPU();
|
||||||
|
PROFILE_MEM(Content);
|
||||||
ZoneText(*outputPath, outputPath.Length());
|
ZoneText(*outputPath, outputPath.Length());
|
||||||
const auto startTime = Platform::GetTimeSeconds();
|
const auto startTime = Platform::GetTimeSeconds();
|
||||||
|
|
||||||
|
|||||||
@@ -310,6 +310,7 @@ namespace
|
|||||||
{
|
{
|
||||||
if (action == FileSystemAction::Delete)
|
if (action == FileSystemAction::Delete)
|
||||||
return;
|
return;
|
||||||
|
PROFILE_CPU();
|
||||||
|
|
||||||
// Get list of assets using this shader file
|
// Get list of assets using this shader file
|
||||||
Array<Asset*> toReload;
|
Array<Asset*> toReload;
|
||||||
@@ -515,6 +516,7 @@ namespace
|
|||||||
{
|
{
|
||||||
if (action == FileSystemAction::Delete || !path.EndsWith(TEXT(".shader")))
|
if (action == FileSystemAction::Delete || !path.EndsWith(TEXT(".shader")))
|
||||||
return;
|
return;
|
||||||
|
PROFILE_CPU();
|
||||||
|
|
||||||
LOG(Info, "Shader \'{0}\' has been modified.", path);
|
LOG(Info, "Shader \'{0}\' has been modified.", path);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user