Repository: godotengine/godot (language: cpp)

Issue:
Horizontally resizing TextEdit with very long contents is very slow even with word wrapping disabled (4.3+)
### Tested versions

4.4.dev7

### System information

Godot v4.4.dev7 - Windows 10 (build 19045) - Multi-window, 2 monitors - OpenGL 3 (Compatibility) - AMD Radeon RX 6800 (Advanced Micro Devices, Inc.; 32.0.12033.1030) - AMD Ryzen 5 7600X 6-Core Processor (12 threads)

### Issue description

When resizing a very large CodeEdit, doing any horizontal resizing takes a very long time, even though the glyph shaping/layout is not changing. It takes the same amount of time as it does when linewrapping is enabled, which is very suspicious and makes me think that it's doing linewrapping-related stuff even when it's disabled.

Instead, horizontal resizing should be as fast as vertical resizing when word wrap is disabled.

Also applies to CodeEdit.

### Steps to reproduce

Add a TextEdit node, paste a lot of text into it (e.g. the contents of a public domain full-length novel like <https://www.gutenberg.org/cache/epub/521/pg521.txt>), then vertically resize (no performance problems at all) and horizontally resize it (huge performance problem). Double check that wrap mode is disabled by default. Then enable it and observe the same performance.

https://github.com/user-attachments/assets/3aa54196-3b65-4314-904b-3e96d9ec0ad0


### Minimal reproduction project (MRP)

N/A (zip file would be annoyingly big, just follow above instructions)


Discussion / hints:
After testing different versions, this performance issue was not present in 4.0 through 4.2.2 but is present in 4.3 and newer (up to and including 4.4dev7)
Okay, checking more, the first prebuilt version of Godot to contain this bug is 4.3 beta3. I don't have a dev environment set up atm to bisect more precisely on a per-commit basis.
I fixed my dev environment and found the commit responsible for this bug. It's e60678f193828c73dc17f3aa5418f2b0d64a0e2f

Fix patch:
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 1fbd2c48c0f0..3bd0a1322b8f 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -7955,12 +7955,13 @@ void TextEdit::_update_wrap_at_column(bool p_force) {
 			}
 			text.set_brk_flags(autowrap_flags);
 			text.set_width(wrap_at_column);
-		} else {
+			text.invalidate_all_lines();
+			_update_placeholder();
+		} else if (text.get_width() != -1) {
 			text.set_width(-1);
+			text.invalidate_all_lines();
+			_update_placeholder();
 		}
-
-		text.invalidate_all_lines();
-		_update_placeholder();
 	}
 
 	// Update viewport.


Test patch: