[Solved]GPU spike and screen lag - 6.99.14

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Farryn
Regular
Posts: 33
Joined: Wed May 10, 2017 10:15 pm
Projects: Diplomatic Relations
IRC Nick: Farryn
Tumblr: princessdealtry
Contact:

[Solved]GPU spike and screen lag - 6.99.14

#1 Post by Farryn »

Hello all,

I updated to the new Ren'Py back on Sunday and since then I've seen noticeable issues with my GPU and lag in my game whenever a screen is being loaded. I've tried the solutions listed at https://www.renpy.org/doc/html/display_problems.html and I double-checked https://www.renpy.org/doc/html/screen_optimization.html to make sure I wasn't doing something horrific, but even with multiple restarts of renpy and my computer the problem remains the same.

Is anyone else experiencing the same issue? It was fine before I updated to the new version but now even just opening renpy(not my actual game) spikes my gpu to 40% and I've watched it hit as high as 80% while running the game. Even the tutorial and the question projects spike it up to at least 50%.

In-game I see the lag whenever I switch screens. For example I have a small fade-in animation that plays before the main menu loads. The animation plays fine but just as the main menu is loading in(in which i remove the faded-in images and add a static background) it lags. The same happens when I navigate to any of the options, load, credits, or gallery screens.

Any thoughts? I'm not ruling out a coding error on my part so I'd like to know if this is something I can fix. :D
Last edited by Farryn on Sun Jan 21, 2018 5:05 pm, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: GPU spike and screen lag - 6.99.14

#2 Post by PyTom »

Well, GPU usage should be increased. That's not a problem.

More concerning is the main menu lag, though that may be due to unpredicted image loads. Can you send me your unpacked game so I can diagnose it and suggest fixes?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Farryn
Regular
Posts: 33
Joined: Wed May 10, 2017 10:15 pm
Projects: Diplomatic Relations
IRC Nick: Farryn
Tumblr: princessdealtry
Contact:

Re: GPU spike and screen lag - 6.99.14

#3 Post by Farryn »

Sent in pm - thank you!

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: GPU spike and screen lag - 6.99.14

#4 Post by PyTom »

Farryn wrote: Fri Jan 19, 2018 8:35 pm In-game I see the lag whenever I switch screens. For example I have a small fade-in animation that plays before the main menu loads. The animation plays fine but just as the main menu is loading in(in which i remove the faded-in images and add a static background) it lags. The same happens when I navigate to any of the options, load, credits, or gallery screens.
The really obvious problem is that you're using a function called ProportionalScale to avoid scaling the gallery images, but it's a terrible function that's slowing things down.

Code: Select all

    def ProportionalScale(img, maxwidth, maxheight):
        currentwidth, currentheight = renpy.image_size(img)
        xscale = float(maxwidth) / float(currentwidth)
        yscale = float(maxheight) / float(currentheight)

        if xscale < yscale:
            minscale = xscale
        else:
            minscale = yscale

        return im.FactorScale(img,minscale,minscale)
The main problem is that the renpy.image_size is a _very_ slow function, as it has to load the image off the disk to read it. It should never be used outside of init code, and probably shouldn't even be used there in a production game. ProportionalScale is being called a ton of times during screen prediction, which is now more aggressive, to the point where the very slow calls interfere with framerate.

I've modified Ren'Py such that it'll simply give up if you ask it to predict a screen that uses renpy.image_size, which'll move the slowdown to before someone clicks on the gallery screen. But I'd recommend getting rid of it entirely, and doing thre work required to actually produce thumbnails for your gallery images. (Without them, the full-size images are _always_ read from disk and decompressed.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
Farryn
Regular
Posts: 33
Joined: Wed May 10, 2017 10:15 pm
Projects: Diplomatic Relations
IRC Nick: Farryn
Tumblr: princessdealtry
Contact:

Re: GPU spike and screen lag - 6.99.14

#5 Post by Farryn »

This is good to know, thank you! I will remove this and switch back to the thumbnails.

-- 5 minute later edit --

I removed the function and switched back to using all thumbnails instead and the lag was fixed immediately. No problem anywhere anymore and the hit to my gpu dropped by 10%.

Thank you very much for taking the time to look into this.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot]