Yet another lag question

The back story is a bit cliched: I just got RPG Maker VX Ace and have started making my first game.   I am noticing that my scenes appear to be lagging and I don't know how to fix it.  

I suspect the ending will be predictable: "Er... why didn't you read thread X, because we explained how to fix your lag problem there."   But, having read about five such threads and making an attempt to implement their solutions hasn't yielded the results I'm hoping for.   And, I'd like to get to root cause before I make the vast (well, large 😉 ) number of maps I intend because fixing them all post facto would be quite a chore.

Here's what I've gleaned (and attempted to do) so far:

- Avoid parallel events wherever possible.   If you must have them, control when they are running using conditionals gating execution of event pages.   I believe that I've only got one or two parallel events running at any given time and they aren't terribly complicated.

- If you must have parallel events, insert Wait commands that will happen on each execution.   I've stuck in Wait(20) commands for all of them that run on each event page execution.

- Delete old events.   All events remove themselves when they aren't needed anymore - especially the parallel ones.   The deletions are all autorun, rather than parallel ... although I suspect that doesn't really matter much since they're all gated on event page conditionals.   So, the parallel events would only execute for a single frame before they remove themselves.

- There was some memory leak around message windows.   HimeWorks presented a solution and I aliased that over the default methods for the map scene and battle scene.

That's the big stuff I gleaned.   Are there things I missed?

Most maps seem to exhibit the problem and it seems to get worse as I play a map.   The effects become visible within about 3-5 minutes, though, so it doesn't take too long.

Here's the big things that I think could be a problem:

- The map is possibly somewhat large?   It doesn't seem like its huge, based on sizes I saw in other posts.   Its 100 x 50.

- The map has a large-ish number of events?   Although not insane: ~130

- Many of those events have Custom move routes that are basically: wander in a random direction within a specified region (using Galv's random_region method).   Do custom move routes like that end up making an event look like a parallel event or will they not be executed unless they are within the 'nearby' threshold?

- Some random script I have installed.   I've accumulated quite a few and written a few myself.   Most seem pretty standard... but are there gotchas that lead to memory leaks or known bad scripts?   I can give you a list of them all.

The fact that it gets slowly worse makes me leap to a memory leak, although the process memory (at least in task manager) appears quite stable.   I've looked around for any sort of profiling tools and come up with nothing - do such things exist?   Failing that, do you have any suggestions or help to offer?   I would be happy to offer you screen shots or just send along the entire game project if that's useful.

Thanks for whatever help you might be able to offer!
If it's a memory leak and/or it happens on all maps, it's likely to be a script (most likely) or a common event (next in line).


So - let's get a list 🙂 Screenshots of your script window showing the list might be a good starting point.


You can disable them all, then re-enable them one by one, testing after each one. If it doesn't happen until you re-enable a particular script, chances are that's the script that's causing it.
The key to removing lag is to identify where it comes from. You already listed most of the options, but unfortunately didn't give enough info about your game for us the even guess which option might cause it.


Two comments are possible on what you wrote, both could lead to the cause:


1) waits on parallel processes


wait works a bit different than most people assume from the name. It basically says "skip execution of this event for X frames, then resume".


That results in a waiting for regular events that run once, but the effect on a parallel process can be tricky, simply because parallel processes are to be restarted every frame.


Because of that the waits on parallel processes should be placed at the end of the process (which might or might not be the end of the content, that depends on branching and event logic)


If you placed the waits differently, they may cause timing problems that only look like lag.


2) scripts


Scripts can cause lag if they modify the main game loop, and you'll need a scripter to identify that.


If everything else fails, we need the full list of your scripts to check for that if you don't know enough about scripting to check that for yourself


Edit: Ninja'd
Thank you so much for the rapid replies.   I'm about to head to bed, but here's a bunch of the info you'd like.   I agree that identifying is the first step; that's the core thing I'm trying to figure out 🙂   I'd normally just attach a profiler and get executing metrics, but I haven't found anything like that for RPG Maker.   So, I'm kicking around in the hopes that someone will hit upon whatever (likely) dumb thing I've done.

Shaz - here is my script window shot. (I could not figure out how to upload to this site, so these are linked from OneDrive ... sorry if that's wrong)

https://onedrive.live.com/redir?resid=DD1693225651FDA9!191897&authkey=!AOvjOKzoA4tjd9E&v=3&ithint=photo%2cpng

Most of those scripts are unmodified, except for the pathfinding algorithm by Jet.   The full text of the modified pathfinding script is here:

https://onedrive.live.com/redir?resid=DD1693225651FDA9!191899&authkey=!AEx0rMtmRYM820c&ithint=file%2ctxt

For my custom scripts, I've just included their full text in another txt file.   The ones near the top are the ones that (in a sane world) would be potentially executing in this scene.   But, I included everything in case there's something more fundamental I am missing.

https://onedrive.live.com/redir?resid=DD1693225651FDA9!191896&authkey=!AHT3nKsxP0jLXpc&ithint=file%2ctxt

I have not tried disabling all the scripts and re-enabling, but if we can't get to something soon-ish I can.   As it takes about 5 mins to get the lag to show up, its a slightly tedious process.   And, from scanning them, I don't _think_ any of the scripts I've got installed should be running in core frame loops such that they could cause a problem like this...   I did try removing the Theo - Antilag script (as it does modify core routines like the event fetching code) and it didn't help.

Andar - I am not 100% sure I followed your parallel events explanation.   I did put the Wait at the end of the script, which I think is what you were suggesting.   But, to be safe, here's an example of one of the parallel event pages and where I stuck the wait:

https://onedrive.live.com/redir?resid=DD1693225651FDA9!191898&authkey=!AOqBDcaSmh5xbAU&v=3&ithint=photo%2cpng

Is that what you meant?   I am actually curious to understand your statement, though, because my default model was to assume that parallel events are effectively running in a separate 'thread' (or some ruby equivalent).   So, I'd have assumed that other than the initial Thread.Start call, nothing was happening for parallel events within the core render\frame loop.   Sounds like that's not really true at all, so I'd love to understand the model so I don't make future mistakes out of ignorance.

I've included a ton (probably more than you wanted) of script information above.   Does that give you more of what you were looking for?   I do apologize for not including sufficient information in the first post.   I wasn't quite sure what'd be of most value.
That is not your script window shot 🙂 It's a copy of the image you gave to Andar.
haha - you are too fast 😉   I think I fixed it like a minute after posting when I was testing that all the links worked anonymously.   Sorry!
At first glance the only interesting scripts on that picture are the pathfinding and Theo's antilag.


I haven't checked any of the scripts, but if the problem is a memory leak, then it has a good chance of being created by the pathfinding, especially if that has been modified.


Most pathfinding scripts use iterations - if those aren't resolved correctly, that will cause memory leaks.


Or it could be a conflict or misconfiguration of the antilag that is supposed to prevent that - because antilags disable the default antilag functions, they can be used to create more lag if the new settings are wrong.


In some cases that is even intentional - Ace stops autonomous movement beyond a certain range, and if the events need to continue movement, I often suggest to use a custom antilag to excempt them from this default antilag.
I'm going to follow this because I too am having some lag issues. I think maybe too many parallel processes may be going on >.<

Can lag also be caused by graphics? As in too big a map, or too much on a map?
I'm going to follow this because I too am having some lag issues. I think maybe too many parallel processes may be going on >.<


Can lag also be caused by graphics? As in too big a map, or too much on a map?
Please make a new topic for your questions - lag can have a lot of causes, and mixing two different cases while searching for them will only cause confusion.
and yes, but only in specific cases and not by grafics in general - ask that in said new topic again.
Please make a new topic for your questions - lag can have a lot of causes, and mixing two different cases while searching for them will only cause confusion.

and yes, but only in specific cases and not by grafics in general - ask that in said new topic again.
My bad. I'll do some hunting around for event issues and then if I have more problems, will post a separate question.
mmm ... I see you are doing pathfinding on an event.


How many events do you have, and how many of them are pathfinding at the same time? Are any of them pathfinding WITHIN the loop, on each iteration? That would certainly slow things down.
Good news: I am pretty confident I've root caused the problem and I have a firing solution on a fix.   I got an FPS display script and measured.   I was getting ~25 FPS and as the level progressed it would start to periodically drop to 20 or 18.   Then it'd bounce back up to nearly 25.   Over time, it would degrade a bit to around an average of 20.   On the kind of machine I'm running on, even 30 FPS for something like this is insanely slow.   Like nearly inexplicably slow...  It runs most modern 3D games at 60FPS with graphics options maxed out.

So, on a lark I sync'ed the game files over to my very old laptop and ran it there.   The result: 60 FPS.   Rock solid.   So, on a machine that's probably 10 times slower, the game ran nearly three times faster.   That conclusively eliminated CPU, memory or graphics horsepower as the culprit.  The laptop was also running the game in the laptop's native resolution - just letterboxed.   Taking that clue, I decided to try running the game NOT in full screen mode on my main machine.   Viola: 60 FPS.

So, the real culprit was something in the resolution.   Either RPG Maker is doing something bad when resetting\using the graphics hardware or (more likely) Windows or the graphics card are turning off optimizations when they are running in such a low resolution.   Heck, I wouldn't be surprised if its just a bug in the driver that no one found b/c who runs in 640x480 these days? 🙂   If someone on the thread cares, I can try attaching a graphics profiler to the game EXE and see if any DirectX insanity pops up.   But, I suspect that without symbols for RPGMaker's EXE output format, I might not get too far.   Still, if someone is interested, I'm happy to try and help debug.

For my immediate problem, a quick search turned up a terrifying script by Zeus81 that replaces RPGMakers full screen (which modifies the graphics driver screen res) with one that doesn't actually change the graphics driver resolution - it just up-samples the game to the current resolution.   I'd like to upgrade it to auto-detect the largest whole number multiple of the game's native resolution which still fits on the current screen (as its coded now, it sizes to fill one dimension - which results in horrible rescaling artifacts OR it'll save a specific scaling value - but that won't work across varying monitor resolutions, so it can't really be used in a game one plans to ship to a PC).   But, using the script, I get full screen and 60 FPS.   So, I think I can solve the remainder of this problem myself with some script hacking.

If you've got any suggestions for scripts you prefer that do something similar or would like anything else from me for your benefit, please let me know.   Otherwise, I think we can call this thread closed.

Thank you for your really prompt engagement and help.   I've been loving RPGMaker.   The time from story idea to functional game in RPGMaker is stunning as compared to tools like Unity or XNA.   And, as a result, I've been having a blast focusing on how to tell a story rather than how to debug the render pipeline.   That's awesome!   And the fact that it's got such an awesome community of people helping folks who are learning it just makes it all the better.   Thanks for making such a cool tool! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/yet-another-lag-question.45953/