Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GDScript] Opportunistically elide array allocations when performing += on Array #76527

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

resistor
Copy link
Contributor

This builds on top of the stack slot elision introduced in #76496

This turns two bytecode operations into one by using the assignment
destination directly as the output of the binary operator. This manifests
in operations like `+=`.
@resistor
Copy link
Contributor Author

Ping

@MewPurPur
Copy link
Contributor

MewPurPur commented May 25, 2023

I can confirm this optimization works.

func _ready() -> void:
	await get_tree().create_timer(1).timeout
	var time_start = Time.get_ticks_usec()
	var a := []
	for i in 6969:
		a += ["element to be added 6969 times"]
	var time = Time.get_ticks_usec() - time_start
	var time_start2 = Time.get_ticks_usec()
	var a2 := []
	for i in 6969:
		a2.append_array(["element to be added 6969 times"])
	var time2 = Time.get_ticks_usec() - time_start2
	print(time/1000.0, "ms")
	print(time2/1000.0, "ms")

Before: 679ms - 2.5ms
Now: 10ms each (slower probably because I tested on dev build)

No immediate regressions found.

@resistor
Copy link
Contributor Author

Ping

@resistor
Copy link
Contributor Author

resistor commented Jul 6, 2023

Now that 4.1 has shipped, can this be reviewed?

@resistor
Copy link
Contributor Author

Ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants