Alright so im making a little program that can read xml files, which i use string.gmatch to filter out all the information i need. But when i run huge files trough the loop, my framerate drops all the way to 0
I can’t really show any functional code, since its for something i will get payed for.
I just wonder if theres any way to make it not eat my framerate and/or if this is a known issue.
Example of the loop im using:
for k,b in string.gmatch(SomeStringHere, SomePattern) do
-- do stuff here
EDIT: got it fixed, used a different way which is way quicker
Still dont know what caused the problem though
How come you need to read an xml file every frame? Why not just read it once, parse the information into something that’s very quick to access, like a table, and access that every frame?
@Ignatz @yojimbo2000 No, no. My bad. Im not calling it every frame, just once at the start.
How impatient are the users? Either put up a “please wait a moment” sign, or place the gmatch in a coroutine to give the user a gradually updating status bar (though that will almost certainly slow it down even further, eg if
yield is inside the
gmatch loop then each iteration would take at least a frame, so I wouldn’t recommend that). Can you at least show us the pattern in the
gmatch? How many iterations are you getting from these huge files?
@Luxizzle How big are the files you’re using. I have a 3,151,541 character dictionary file (300249 words) that I use. If I do a string.gmatch on the last word, it reads the whole file in the blink of an eye. What are you doing with the results of gmatch, maybe that’s what’s slowing things down.
Anchoring the search with ^ and $ helps a lot.
@Luxizzle Since you don’t want to show any code or say what you’re doing, I’ll take a guess that you want to view selected information from an xml file. Here’s an example I have that reads an html file, but xml is probably the same. I have this example setup to show any text between the < and > characters in the file. You can drag your finger up or down the screen to see all the lines. Let me know if this is usable or not close to what you want.
msg="Please wait, reading file"
for a,b,c in string.gmatch(data,"(<)(.-)(>)") do
background(40, 40, 50)
if #tab==0 then
for z=st,en do
if t.state==MOVING then