Browse Source

ResourceLoader: Optimize remap check by deferring until a non-mutex zone

Pedro J. Estébanez 1 year ago
parent
commit
5c970db2e4
2 changed files with 5 additions and 6 deletions
  1. 5 4
      core/io/resource_loader.cpp
  2. 0 2
      core/io/resource_loader.h

+ 5 - 4
core/io/resource_loader.cpp

@@ -342,8 +342,10 @@ void ResourceLoader::_run_load_task(void *p_userdata) {
 	}
 	}
 	// --
 	// --
 
 
+	bool xl_remapped = false;
+	const String &remapped_path = _path_remap(load_task.local_path, &xl_remapped);
 	Error load_err = OK;
 	Error load_err = OK;
-	Ref<Resource> res = _load(load_task.remapped_path, load_task.remapped_path != load_task.local_path ? load_task.local_path : String(), load_task.type_hint, load_task.cache_mode, &load_err, load_task.use_sub_threads, &load_task.progress);
+	Ref<Resource> res = _load(remapped_path, remapped_path != load_task.local_path ? load_task.local_path : String(), load_task.type_hint, load_task.cache_mode, &load_err, load_task.use_sub_threads, &load_task.progress);
 	if (MessageQueue::get_singleton() != MessageQueue::get_main_singleton()) {
 	if (MessageQueue::get_singleton() != MessageQueue::get_main_singleton()) {
 		MessageQueue::get_singleton()->flush();
 		MessageQueue::get_singleton()->flush();
 	}
 	}
@@ -402,14 +404,14 @@ void ResourceLoader::_run_load_task(void *p_userdata) {
 			load_task.resource->set_path_cache(load_task.local_path);
 			load_task.resource->set_path_cache(load_task.local_path);
 		}
 		}
 
 
-		if (load_task.xl_remapped) {
+		if (xl_remapped) {
 			load_task.resource->set_as_translation_remapped(true);
 			load_task.resource->set_as_translation_remapped(true);
 		}
 		}
 
 
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
 		load_task.resource->set_edited(false);
 		load_task.resource->set_edited(false);
 		if (timestamp_on_load) {
 		if (timestamp_on_load) {
-			uint64_t mt = FileAccess::get_modified_time(load_task.remapped_path);
+			uint64_t mt = FileAccess::get_modified_time(remapped_path);
 			//printf("mt %s: %lli\n",remapped_path.utf8().get_data(),mt);
 			//printf("mt %s: %lli\n",remapped_path.utf8().get_data(),mt);
 			load_task.resource->set_last_modified_time(mt);
 			load_task.resource->set_last_modified_time(mt);
 		}
 		}
@@ -531,7 +533,6 @@ Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path,
 		{
 		{
 			ThreadLoadTask load_task;
 			ThreadLoadTask load_task;
 
 
-			load_task.remapped_path = _path_remap(local_path, &load_task.xl_remapped);
 			load_task.load_token = load_token.ptr();
 			load_task.load_token = load_token.ptr();
 			load_task.local_path = local_path;
 			load_task.local_path = local_path;
 			load_task.type_hint = p_type_hint;
 			load_task.type_hint = p_type_hint;

+ 0 - 2
core/io/resource_loader.h

@@ -173,7 +173,6 @@ private:
 		bool need_wait = true;
 		bool need_wait = true;
 		LoadToken *load_token = nullptr;
 		LoadToken *load_token = nullptr;
 		String local_path;
 		String local_path;
-		String remapped_path;
 		String type_hint;
 		String type_hint;
 		float progress = 0.0f;
 		float progress = 0.0f;
 		float max_reported_progress = 0.0f;
 		float max_reported_progress = 0.0f;
@@ -182,7 +181,6 @@ private:
 		ResourceFormatLoader::CacheMode cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE;
 		ResourceFormatLoader::CacheMode cache_mode = ResourceFormatLoader::CACHE_MODE_REUSE;
 		Error error = OK;
 		Error error = OK;
 		Ref<Resource> resource;
 		Ref<Resource> resource;
-		bool xl_remapped = false;
 		bool use_sub_threads = false;
 		bool use_sub_threads = false;
 		HashSet<String> sub_tasks;
 		HashSet<String> sub_tasks;
 	};
 	};