Skip to content
New issue

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

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

Already on GitHub? # to your account

[blitz.mod] Debug builds: GCSuspend/GCResume for each "local block" #316

Open
GWRon opened this issue Mar 22, 2024 · 0 comments
Open

[blitz.mod] Debug builds: GCSuspend/GCResume for each "local block" #316

GWRon opened this issue Mar 22, 2024 · 0 comments

Comments

@GWRon
Copy link
Contributor

GWRon commented Mar 22, 2024

This is not a bug report but some kind of "question".

Assume this code here:

Function ForLoop()
	Local res:int
	Local t:Int = Millisecs()
	For Local x:int = 0 to 10000
		For Local y:int = 0 to 10000
			res :+ 1
		Next
	Next
	print "ForLoop took " + (Millisecs()-t) +" ms."
End Function

This results (for debug builds) in this c code:

void _m_untitled1_ForLoop(){
	BBINT bbt_res=0;
	BBINT bbt_t=0;
	struct BBDebugScope_2 __scope = {
		BBDEBUGSCOPE_FUNCTION,
		"ForLoop",
		{
			{
				BBDEBUGDECL_LOCAL,
				"res",
				"i",
				.var_address=&bbt_res
			},
			{
				BBDEBUGDECL_LOCAL,
				"t",
				"i",
				.var_address=&bbt_t
			},
			{
				BBDEBUGDECL_END
			}
		}
	};
	bbOnDebugEnterScope((BBDebugScope *)&__scope);
	struct BBDebugStm __stmt_0 = {0x558ac721d846ce0d, 18, 0};
	bbOnDebugEnterStm(&__stmt_0);
	bbt_res=0;
	struct BBDebugStm __stmt_1 = {0x558ac721d846ce0d, 19, 0};
	bbOnDebugEnterStm(&__stmt_1);
	bbt_t=bbMilliSecs();
	struct BBDebugStm __stmt_2 = {0x558ac721d846ce0d, 20, 0};
	bbOnDebugEnterStm(&__stmt_2);
	{
		BBINT bbt_x=0;
		for(;(bbt_x<=10000);bbt_x=(bbt_x+1)){
			struct BBDebugScope_1 __scope = {
				BBDEBUGSCOPE_LOCALBLOCK,
				0,
				{
					{
						BBDEBUGDECL_LOCAL,
						"x",
						"i",
						.var_address=&bbt_x
					},
					{
						BBDEBUGDECL_END
					}
				}
			};
			bbOnDebugEnterScope((BBDebugScope *)&__scope);
			struct BBDebugStm __stmt_0 = {0x558ac721d846ce0d, 21, 0};
			bbOnDebugEnterStm(&__stmt_0);
			{
				BBINT bbt_y=0;
				for(;(bbt_y<=10000);bbt_y=(bbt_y+1)){
					struct BBDebugScope_1 __scope = {
						BBDEBUGSCOPE_LOCALBLOCK,
						0,
						{
							{
								BBDEBUGDECL_LOCAL,
								"y",
								"i",
								.var_address=&bbt_y
							},
							{
								BBDEBUGDECL_END
							}
						}
					};
					bbOnDebugEnterScope((BBDebugScope *)&__scope);
					struct BBDebugStm __stmt_0 = {0x558ac721d846ce0d, 22, 0};
					bbOnDebugEnterStm(&__stmt_0);
					bbt_res+=1;
					bbOnDebugLeaveScope();
				}
			}
			bbOnDebugLeaveScope();
		}
	}
	struct BBDebugStm __stmt_3 = {0x558ac721d846ce0d, 25, 0};
	bbOnDebugEnterStm(&__stmt_3);
	brl_standardio_Print(bbStringConcat(bbStringConcat(((BBString*)&_s0),bbStringFromInt(bbMilliSecs()-bbt_t)),((BBString*)&_s1)));
	bbOnDebugLeaveScope();
}

(adding nodebug or doing a release build becomes:)

void _m_untitled1_ForLoopNoDebug(){
	BBINT bbt_res=0;
	BBINT bbt_t=bbMilliSecs();
	{
		BBINT bbt_x=0;
		for(;(bbt_x<=10000);bbt_x=(bbt_x+1)){
			{
				BBINT bbt_y=0;
				for(;(bbt_y<=10000);bbt_y=(bbt_y+1)){
					bbt_res+=1;
				}
			}
		}
	}
	brl_standardio_Print(bbStringConcat(bbStringConcat(((BBString*)&_s0),bbStringFromInt(bbMilliSecs()-bbt_t)),((BBString*)&_s1)));
}

As you see - each statement is prepended by a bbOnDebugEnterStm (no ...leave needed) and that function does not start/stop the GC.
But the EnterScope and LeaveScope-functions do.

Could there be a more "smart" approach (I know "smart" often means "more error prone" :D) to avoid affecting the GC so much?
Maybe doing some "nesting" (each "enterscope" increases a value, each "leavescope" decreases a value) with the GC only being enabled/disabled on "level 0" ?
Dunno about "deeply nested" stuff (where a lot memory is "allocated/freed" - with the GC being disabled).

Maybe you have other ideas -- maybe the GC-enable/disable is not needed at all?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant