Skip to content

feature proposal: cache script paths #24

@phosphorylation

Description

@phosphorylation

I noticed that _format_data incurs a significant overhead by looking up the script names and class names. I added two simple dictionary as cache to hide it, something like this.

static var GLOBAL_PATH_FILTER_CACHE := {}
static var GLOBAL_SCRIPT_CACHE := {}

static func _get_format_data(entry:LogStream.LogEntry)->Dictionary:
	var now = Time.get_datetime_dict_from_system(USE_UTC_TIME_FORMAT)
	
	var log_call = null
	var script = ""
	var script_class_name = ""
	if !entry.stack.is_empty():
		log_call = entry.stack[0]
		var source = log_call["source"]
		if source in GLOBAL_SCRIPT_CACHE:
			script = GLOBAL_SCRIPT_CACHE[source]
		else:
			script = source.split("/")[-1]
			GLOBAL_SCRIPT_CACHE[source] = script
		var result
		if entry in GLOBAL_PATH_FILTER_CACHE:
			result = GLOBAL_PATH_FILTER_CACHE[entry]
		else:
			result = GLOBAL_PATH_LIST.filter(func(entry):return entry["path"] == source)
			GLOBAL_PATH_FILTER_CACHE[entry] = result
		script_class_name = script if result.is_empty() else result[0]["class"]

Should hold as long as the scripts don't change while game's running. you are welcomed to test the improvements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions