Problem with optimization

im using godot version 4.7.2 stable

so i have an upgrade tree, and once i hover over an upgrade with my mouse, it makes a colorrect with a richtextlabel that shows description and effect, but when i hover over it for the first time, it freezes for a lil bit (happens with every upgrade once), heres the code

@export var upgrade_description : String

func _ready() -> void:
	pressed.connect(on_click)
	mouse_entered.connect(on_hover)
	mouse_exited.connect(on_hover_exit)
	
	#this entire section is to preload all the upgrades's properties so that it doesnt lag
	upgrade_desc_label.global_position = rect_background.global_position
	upgrade_desc_label.size = Vector2(500,200)
	upgrade_desc_label.text = upgrade_description
	upgrade_desc_label.z_index = 11
	upgrade_desc_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
	upgrade_desc_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
	upgrade_desc_label.add_theme_font_override("normal_font",custom_font)
	upgrade_desc_label.add_theme_font_size_override("normal_font_size",24)
	upgrade_desc_label.push_outline_size(20)
	upgrade_desc_label.visible = false
	#modify a colorrect to contain the description
	rect_background.global_position = get_global_mouse_position() + Vector2(20,20)
	rect_background.z_index = 10
	rect_background.visible = false
	rect_background.color = Color.from_hsv(0.083, 0.095, 0.165, 0.882)
	rect_background.size = Vector2(500,200)
	
	rect_background.mouse_filter = Control.MOUSE_FILTER_IGNORE
	add_child(rect_background)
	rect_background.add_child(upgrade_desc_label)

#if the node is supposed to be visible, make it visible.
func _process(_delta: float) -> void:
	if is_available:
		visible = true
	elif !is_available:
		visible = false
	
	#part to update hovers's text box
	if isHoverActive:
		rect_background.global_position = get_global_mouse_position() + Vector2(20,20)
		upgrade_desc_label.position = Vector2.ZERO

#loads the rectangle, font and a variable to check if the mouses on the upg
var isHoverActive = false
var rect_background = ColorRect.new()
var upgrade_desc_label = RichTextLabel.new()
var custom_font = preload("res://assets/fonts/LowresPixel-Regular.otf")


func on_hover():
	if isHoverActive == false:
		rect_background.visible = true
		upgrade_desc_label.visible = true
		isHoverActive = true

func on_hover_exit():
	rect_background.visible = false
	upgrade_desc_label.visible = false
	isHoverActive = false

That could be shader caching. Doesn’t it go away after first run?

While re-inventing the wheel is a popular tradition, did you look through the existing tooltip-ish addons?
I think Modular UI Architecture might be a good fit for your tooltip needs