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

virtual int debug_get_stack_level_line(int p_level) const override;
	virtual String debug_get_stack_level_function(int p_level) const override;
	virtual String debug_get_stack_level_source(int p_level) const override;
	virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
	virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
	virtual ScriptInstance *debug_get_stack_level_instance(int p_level) override;
	virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
	virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1) override;
	virtual void reload_all_scripts() override;
	virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override;
	virtual void frame() override;
	virtual void get_public_functions(List<MethodInfo> *p_functions) const override;
	virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const override;
	virtual void get_public_annotations(List<MethodInfo> *p_annotations) const override;
	virtual void profiling_start() override;
	virtual void profiling_stop() override;
	virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override;
	virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override;
	
	virtual void get_recognized_extensions(List<String> *p_extensions) const override;
	
	virtual bool handles_global_class_type(const String &p_type) const override;
	virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr) const override;
	void add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass);
	Ref<GDScript> get_orphan_subclass(const String &p_qualified_name);
	Ref<GDScript> get_script_by_fully_qualified_name(const String &p_name);
	GDScriptLanguage();
	~GDScriptLanguage();
};
class ResourceFormatLoaderGDScript : public ResourceFormatLoader {