### Godot version

Godot 4.1-beta2

### System information

Manjaro Gnome, Intel Core i7-11800H

### Issue description

On a relatively modern laptop (Intel Core i7-11800H), in a scene with many scripted nodes (total of 900+ with roughly half of them scripted), adding or duplicating a node freezes the editor for several seconds. Godot 4.0.2 handles such scenes much better!

Here is a flame graph captured while repeatedly duplicating simple Marker2D nodes with Ctrl+D in a complicated scene:
![Screenshot from 2023-06-15 23-54-38](https://github.com/godotengine/godot/assets/2766569/d0019f17-9b82-4a26-9b47-71fa7a3bef3a)

Performance data file to use with hotspot v1.4.1 (relevant data starts at the 75-second mark and lasts about 20+ seconds):
[perf.data.perfparser.zip](https://github.com/godotengine/godot/files/11763700/perf.data.perfparser.zip)



### Steps to reproduce

1) Add 1000 nodes with a script attached.
2) Duplicate a node and witness lags.

Also affects scrolling the scene tree dock.

### Minimal reproduction project

[add_node_lags_repro.zip](https://github.com/godotengine/godot/files/11763731/add_node_lags_repro.zip)

EditorFileDialog::set_default_display_mode((EditorFileDialog::DisplayMode)EDITOR_GET("filesystem/file_dialog/display_mode").operator int());
			bool theme_changed =
					EditorSettings::get_singleton()->check_changed_settings_in_group("interface/theme") ||
					EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/font") ||
					EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/main_font") ||
					EditorSettings::get_singleton()->check_changed_settings_in_group("interface/editor/code_font") ||
					EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/theme") ||
					EditorSettings::get_singleton()->check_changed_settings_in_group("text_editor/help/help") ||
					EditorSettings::get_singleton()->check_changed_settings_in_group("filesystem/file_dialog/thumbnail_size") ||
					EditorSettings::get_singleton()->check_changed_settings_in_group("run/output/font_size") ||
					EditorSettings::get_singleton()->check_changed_settings_in_group("interface/touchscreen/increase_scrollbar_touch_area") ||
					EditorSettings::get_singleton()->check_changed_settings_in_group("interface/touchscreen/scale_gizmo_handles");
			if (theme_changed) {
				theme = create_custom_theme(theme_base->get_theme());
				DisplayServer::set_early_window_clear_color_override(true, theme->get_color(SNAME("background"), SNAME("Editor")));
				theme_base->set_theme(theme);
				gui_base->set_theme(theme);
				get_window()->set_theme(theme);
				gui_base->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("Background"), SNAME("EditorStyles")));
				main_vbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, gui_base->get_theme_constant(SNAME("window_border_margin"), SNAME("Editor")));
				main_vbox->add_theme_constant_override("separation", gui_base->get_theme_constant(SNAME("top_bar_separation"), SNAME("Editor")));
				scene_root_parent->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("Content"), SNAME("EditorStyles")));
				bottom_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("BottomPanel"), SNAME("EditorStyles")));
				tabbar_panel->add_theme_style_override("panel", gui_base->get_theme_stylebox(SNAME("tabbar_background"), SNAME("TabContainer")));
				scene_tabs->add_theme_constant_override("icon_max_width", gui_base->get_theme_constant(SNAME("class_icon_size"), SNAME("Editor")));
				scene_tab_add_ph->set_custom_minimum_size(scene_tab_add->get_minimum_size());
				main_menu->add_theme_style_override("hover", gui_base->get_theme_stylebox(SNAME("MenuHover"), SNAME("EditorStyles")));
			}
			scene_tabs->set_max_tab_width(int(EDITOR_GET("interface/scene_tabs/maximum_width")) * EDSCALE);
			_update_scene_tabs();