### 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)

void clear(GDScript::ClearData *p_clear_data = nullptr);
	virtual bool is_valid() const override { return valid; }
	virtual bool is_abstract() const override { return false; } 
	bool inherits_script(const Ref<Script> &p_script) const override;
	GDScript *find_class(const String &p_qualified_name);
	bool has_class(const GDScript *p_script);
	GDScript *get_root_script();
	bool is_root_script() const { return _owner == nullptr; }
	String get_fully_qualified_name() const { return fully_qualified_name; }
	const HashMap<StringName, Ref<GDScript>> &get_subclasses() const { return subclasses; }
	const HashMap<StringName, Variant> &get_constants() const { return constants; }
	const HashSet<StringName> &get_members() const { return members; }
	const GDScriptDataType &get_member_type(const StringName &p_member) const {