Letting Firefox catch a breath while parsing LARGE

Monkey Targets Forums/HTML5/Letting Firefox catch a breath while parsing LARGE

MonkeyPlotter(Posted 2016) [#1]
...files.

I'm managing to parse data files of up to 8KBytes, however, when attempting to parse files of say, 80Kbytes, the Browser doesn't like it too much.

[EDIT] This problem was attributed to printing out too much debug to the printing buffer at the bottom of the browser, top tip - keep your debug beneath a couple of 100 lines.

It initially reports - 'a script is not responding' I let it continue and then the whole browser 'greys out' before seeming to become totally unresponsive.

Is there a way to let the Browser catch a breath - or am I simply expecting too much to expect a browser to be able to deal with such large (ish) amounts of data?


muddy_shoes(Posted 2016) [#2]
There's nothing large about an 80KB file as such. The unresponsive message suggests that whatever your parsing code is doing it's taking a very long time and not returning to the event handler while doing it. The answer is to speed up your code and/or change it so that it does parsing in small amounts at a time and then returning to the event loop.


Sicilica(Posted 2016) [#3]
I doubt this is OP's problem at only 80K, but is there any way to stream files on the HTML5 target? Neither FileStream nor TcpStream are supported in browsers AFAIK, and on a large enough file you wouldn't want to use a blocking method to load it. In raw JS you would want to use xhr to load it asynchronously and be told when it completes, but....


MonkeyPlotter(Posted 2016) [#4]
Thanks Sicilica and muddy_shoes, will investigate shortly.


MonkeyPlotter(Posted 2016) [#5]
The answer is to speed up your code and/or change it so that it does parsing in small amounts at a time and then returning to the event loop.
Having a bash at this now.


MonkeyPlotter(Posted 2016) [#6]
I think the root of my problem is that the print buffer for my debug is being filled up. Is there a way to periodically flush what is in the print buffer to the debug area in the bottom of the browser?

[EDIT] drastically reduced the debug I'm putting out - solved.


k.o.g.(Posted 2016) [#7]
Maybe it helps you? quick done an example

Strict

Import mojo

#If LANG = "js" Then
Extern Private
	Function ClearDebugOutput:Void() = "(function(){var el=document.getElementById(~qGameConsole~q);if(el){el.value=~q~q;}})"
Public
#Else
Function ClearDebugOutput:Void()
End
#End


Class Test Extends App
	Field _i:Int = 0
	Method OnCreate:Int()
		SetUpdateRate(60)
		Return 0
	End
	
	Method OnRender:Int()
		Cls(0, 0, 0)
		DrawText(Millisecs(), DeviceWidth() / 2, DeviceHeight() / 2, 0.5, 0.5)
		Return 0
	End
	
	Method OnUpdate:Int()
		_i += 1
		Print("I'm Debug!")
		
		If _i > 100 Then
			_i = 0
			ClearDebugOutput()
			Print "Cleared"
		End
		Return 0
	End
End

Function Main:Int()
	New Test()
	Return 0
End



MonkeyPlotter(Posted 2016) [#8]
@K.o.g. , thanks for the feedback - a great way of clearing out the debug output.