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

Some more GDScript performance optimizations #11518

Merged
merged 4 commits into from
Sep 25, 2017

Conversation

hpvb
Copy link
Member

@hpvb hpvb commented Sep 23, 2017

Two new changes to GDScript:

  • On compilers that support computed goto use it to dispatch opcodes in GDScript::call()
  • Remove several indexing checks on DEBUG_RELEASE, these shouldn't appear in released games.

And an optimization for safe_refcount:

  • Allow better inlining of safe_refcount implementations. Not a huge win but very little effort and the effect is measurable.

Overall improvement is about 20% for the following GDScript

func _ready():
	var time_before = OS.get_ticks_msec()

	var c
	for i in range(10000000):
		var next 
		var first = 1
		var second = 2
		for c in range(40):
			next = first + second
			first = second
			second = next
		c = next
	print(c)

	var total_time = OS.get_ticks_msec() - time_before
	print("Time taken: " + str(total_time))
	get_tree().quit()
	pass

Regression testing has been done with 2d/platformer, 3d/platformer, goltorus, and this program.

@akien-mga akien-mga added this to the 3.0 milestone Sep 23, 2017
@hpvb hpvb force-pushed the gdscript-direct-dispatch branch from b91a0dd to 0922c73 Compare September 23, 2017 20:03
@hpvb hpvb changed the title Some more GDScript performance optimizations [WIP] Some more GDScript performance optimizations Sep 23, 2017
@hpvb hpvb force-pushed the gdscript-direct-dispatch branch 3 times, most recently from 21de102 to 9cd7eca Compare September 24, 2017 22:59
@hpvb hpvb changed the title [WIP] Some more GDScript performance optimizations Some more GDScript performance optimizations Sep 25, 2017
@hpvb
Copy link
Member Author

hpvb commented Sep 25, 2017

@karroffel @reduz @akien-mga @bojidar-bg I think this is done now. It'd be great if one of you could have a look and merge if you see no problems.

I'm working on another PR to optimize the most common operations based on the addressing modes of the parameters. Once that's done for 3.0 I think these types of optimizations are done. I think I could eek out another 10 - 15% by making many more 1 - 2% changes but I'm not entirely sure if this is worth doing.

On compulers that define __GNUC__ use computed goto to directly dispatch
the next instruction rather than going through another switch statement.
This saves a jump and some comparisons.

In tight loops this is is roughly 10% faster than the switch() method.
These errors shouldn't be possible on a tested game. Remove the checks
on release. Shaves about 10% off of tight loops.
Differences with this aren't huge but the effort is minimal, in some
workloads gain a couple of percent of performance.
Not doing this was a bit of an oversight
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.

2 participants