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: Blank/comment script lines use up CPU cycles inside for loop #33089

Closed
Tracked by #40488
wyattbiker opened this issue Oct 26, 2019 · 9 comments
Closed
Tracked by #40488

Comments

@wyattbiker
Copy link

Godot version:
3.2.alpha2 IDE
OS/device including version:
Mac OS X, Mojave

Issue description:
GDScript: Blank/comment script lines use up CPU cycles inside for loop. Seems to be treated like a pass statement. Also the debugger single steps into comments/blank lines (instead of over) which is why I was wondering of the impact.

Steps to reproduce:
Create a Control scene and add script below. Test with blank lines and without blank lines.
For one blank line 1000 iterations on my system I get 185μs vs 148μs. Additional blank/comment lines you add the greater the cpu time.

extends Control
func _ready() -> void:
	var end_time:int
	var x:int = 0
	var start_time:int=OS.get_ticks_usec()
	for i in range(1000):
		
		x += 1
	end_time=OS.get_ticks_usec() 
	print("Elapsed μs: ", end_time - start_time)
	pass # Replace with function body.
@Calinou
Copy link
Member

Calinou commented Oct 26, 2019

Does this slowdown occur in a project exported in release mode?

@wyattbiker
Copy link
Author

I export to a .dmg file which is the installer format for Mac OS X. I install it and run. It has same behaviour. ie CPU cycles are consumed on blank/comments.

Here are the settings. I don't see a specific Release Mode flag.
image

@bruvzg
Copy link
Member

bruvzg commented Oct 26, 2019

Does this slowdown occur in a project exported in release mode?

I can't reproduce it with release build, only with debug, here are results (average of 5000 runs with 1000 iterations each):

Extra Lines Release Time Debug Time
0 53 μs 231 μs
1 52 μs 285 μs
10 52 μs 525 μs
100 52 μs 3011 μs

Edit: Compiled GDScript do preserve tokens for each empty line in any export config.

@bruvzg
Copy link
Member

bruvzg commented Oct 26, 2019

I don't see a specific Release Mode flag.

It's in the corner of file selection dialogue, after you click Export Project.
Screenshot 2019-10-26 at 19 47 29

@wyattbiker
Copy link
Author

But yes, blank lines do not take up CPU time when Debug Flag is unchecked. Not as serious, but would be worthwhile pointing out that blanks and comments are treated as 'pass' during dev.

Irrelevant comment: Didn't see that flag on the fileopen dialog. Strange place for it in my opinion.

@Calinou
Copy link
Member

Calinou commented Oct 26, 2019

Irrelevant comment: Didn't see that flag on the fileopen dialog. Strange place for it in my opinion.

Feel free to suggest improvements in #20219 🙂

@GoDino
Copy link

GoDino commented Jan 28, 2020

I believe a debugger should not step into blank lines/comments at all. With a small change this could be achieved, which should fix the bug. Would that be ok?
Already have a working version that does this, would be happy to make a PR.

@Calinou
Copy link
Member

Calinou commented Jan 28, 2020

@GoDino Feel free to open a pull request for this 🙂

@KoBeWi
Copy link
Member

KoBeWi commented Dec 18, 2020

Fixed in 4.0

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

No branches or pull requests

5 participants