Closed aiaimimi0920 closed 5 days ago
This issue will indeed affect the game,
The game I am currently working on has an achievement interface with 100 achievements, and then dynamically creates text in the form of richerlabel_tscn.instantite() in the game.
So now every time I enter the achievement interface, I get stuck for about 1 second.
Although I can try to solve this problem through dynamic loading, But I believe it may be a problem that the richerlabel control needs to address
Hmm, when I set bbcode
before calling add_child
it initialized faster and instantiated faster than the original RichTextLabel
. But I see it is slower when setting bbcode
after add_child
. So something is probably being called twice. I'll look into it eventually.
Also what operating system do you use? I developed on Linux, so many there is an eccentricity.
extends Control
@onready var a: VBoxContainer = $VBoxContainer/a
@onready var b: VBoxContainer = $VBoxContainer/b
@onready var c: VBoxContainer = $VBoxContainer/c
const RICHER_TEXT_LABEL = preload("res://richer_text_label.tscn")
func _ready() -> void:
var t := Time.get_ticks_msec()
for x in 1000:
var rt := RichTextLabel.new()
rt.bbcode_enabled = true
rt.fit_content = true
rt.text = "[rainbow freq=1.0 sat=0.8 val=0.8]test[/rainbow]"
a.add_child(rt)
var tot := Time.get_ticks_msec() - t
print(tot)
var t2 := Time.get_ticks_msec()
for x in 1000:
var rt := RicherTextLabel.new()
rt.bbcode_enabled = true
rt.fit_content = true
rt.bbcode = "[rainbow freq=1.0 sat=0.8 val=0.8]test[]"
b.add_child(rt)
var tot2 := Time.get_ticks_msec() - t2
print(tot2)
var t3 := Time.get_ticks_msec()
for x in 1000:
var rt := RICHER_TEXT_LABEL.instantiate()
rt.bbcode_enabled = true
rt.fit_content = true
rt.bbcode = "[rainbow freq=1.0 sat=0.8 val=0.8]test[]"
c.add_child(rt)
var tot3 := Time.get_ticks_msec() - t3
print(tot3)
print("new: ", tot2 / float(tot))
print("ins: ", tot3 / float(tot))
1553
1212
1261
new: 0.78042498390212
ins: 0.81197681905988
I used the exact same code as you, but I couldn't get your results.
This is my result:
313
215
7570
new: 0.68690095846645
ins: 24.185303514377
This is my environment: Godot v4.4.dev2 - Windows 10.0.22631 - OpenGL 3 (Compatibility) - NVIDIA GeForce RTX 2080 Ti (NVIDIA; 31.0.15.4633) - 12th Gen Intel(R) Core(TM) i5-12400F (12 Threads)
Based on your code, I have observed that using RicherTextLabel.new() for initialization does significantly reduce creation time, but in practical use, I believe using instantiate() to create scene is a normal behavior.
For example, this is my “achievement scene“: It includes two RicherTextLabel :NameLabel 和 DescLabel
If I have to create this control through code, I will lose the advantage of manipulating the control to adjust its position through the editor
I conducted another test and found that the time is normal in the exported program:
Windows Godot Editor runtime scene: 251 213 7552 new: 0.84860557768924 ins: 30.0876494023904
Run Windows Export exe: 186 144 262 new: 0.7741935483871 ins: 1.40860215053763
If this 30 fold time difference only occurs in the editor environment, then I can reluctantly accept it.
But it would be even better if it could be solved
Secondly, 1.4 is twice that of 0.7. Is there something that has been repeatedly initialized?
That helpfully narrows it down to some places.
I've pushed a number of changes that might have been a culprit, but there may be breaking changes too.
@chairfull After testing, your push effectively solved this problem
This is the result of running in the godot editor in windows
244
185
204
new: 0.75819672131148
ins: 0.83606557377049
Thank you for your prompt assistance and for creating this plugin
No problem!
Here are two examples:
Their average time is
The 27 times creation time difference seems a bit unreasonable test_richer_text_label.zip