gurrgur / er-patcher

Elden Ring enhancement patches (ultrawide support, custom frame rate limits and more) seamlessly integrated with steam.
MIT License
311 stars 25 forks source link

fix: save memory #2

Closed DinCahill closed 2 years ago

DinCahill commented 2 years ago

Hi, thanks for making this script. I was looking at the code, and noticed that exe and exe_hex aren't being freed, so the script hogs a lot of memory while the game is running.

Before:

memory usage before

Fixed:

memory usage after


I used memory-profiler to do the following analysis:

Reading the exe takes up the expected 78.9MB, and the hex version is twice as big at 157.7MB.

    25     21.4 MiB      0.0 MiB           1       exe_name = Path("eldenring.exe")
    26    100.3 MiB      0.0 MiB           2       with open(exe_name, "rb") as f:
    27    100.3 MiB     78.9 MiB           1           exe = f.read()
    28    258.0 MiB    157.7 MiB           1       exe_hex = exe.hex()

The memory stays in use until the end of the script:

    81    258.1 MiB      0.0 MiB           1       os.rmdir(patched_exe_dir)

I made two changes:

gurrgur commented 2 years ago

Hey, thanks for the fix! Definitely makes sense to save some memory. I'll merge it right in :)