### Godot version

Godot v4.2.rc2

### System information

Godot v4.2.rc2 - Ubuntu 22.04.3 LTS 22.04 - X11 - Vulkan (Forward+) - integrated Intel(R) UHD Graphics (CML GT2) () - Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz (12 Threads)

### Issue description

When there is a lot of dependencies between types defined with class_name or class, the quitting time for game (and editor) grows exponentially.


With a "real" project (nb of scripts: 97, nb lignes of code: 11638, nb dependencies between script: 336) the quitting time is ~8.0s.
I could manage to reduce it to ~5.0s just by moving an inner class from one file to another.

On a "toy" project, with N scripts doing nothing except depending on each others, the quitting time seems exponential:

- 40 scripts : 1.5s
- 50 scripts : 2.5s
- 60 scripts : 4.5s
- 70 scripts : 8.4s
- 80 scripts : 15.7s
- 90 scripts : 27.1s
- 100 scripts : 46.8s

Adding the dependencies as a type check (`if my_var is MyType`) triggers the issue.
Adding the dependencies as a type creation (`MyType.new()`) triggers the issue.
Adding the dependencies as type hinting (`var my_var : MyType`) doesn't triggers the issue.

Adding inner (unused) classes inside these script increases a lot the time.

The dependencies being cyclical or not doesn't seems to change the behavior.

Same issue with 4.1.2-stable.

### Steps to reproduce

1) Create N scripts, each depending on each others

for example for script0.gd:

```
class_name Script0

static func some_func():
    print(Script0.new())
    print(Script1.new())
    print(Script2.new())
    print(Script3.new())
    ...

```

2) in the script of the main scene, add a dependency to one of the N inter-depending scripts, for example with `print(null is Script0)`

3) then quit directly the scene, with `get_tree().quit()`

4) launch the main scene

If N is high enough (>50), it will start to quit directly, but the quitting time will be long.

5) quit the editor.

The quitting time will also be quite long.

note: a python script has been provided in the minimal project to create all the N inter-depending gdscript scripts of step 1.

### Minimal reproduction project

[quitting_time_dependencies.zip](https://github.com/godotengine/godot/files/13476840/quitting_time_dependencies.zip)

while (sptr) {
		{
			HashMap<StringName, GDScript::MemberInfo>::ConstIterator E = sptr->static_variables_indices.find(p_name);
			if (E) {
				const GDScript::MemberInfo *member = &E->value;
				Variant value = p_value;
				if (member->data_type.has_type && !member->data_type.is_type(value)) {
					const Variant *args = &p_value;
					Callable::CallError err;
					Variant::construct(member->data_type.builtin_type, value, &args, 1, err);
					if (err.error != Callable::CallError::CALL_OK || !member->data_type.is_type(value)) {
						return false;
					}
				}
				if (member->setter) {
					const Variant *args = &value;
					Callable::CallError err;
					callp(member->setter, &args, 1, err);
					return err.error == Callable::CallError::CALL_OK;
				} else {
					sptr->static_variables.write[member->index] = value;
					return true;
				}
			}
		}
		{
			HashMap<StringName, GDScriptFunction *>::Iterator E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._set);
			if (E) {
				Variant name = p_name;
				const Variant *args[2] = { &name, &p_value };