Closed DinCahill closed 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.
exe
exe_hex
Before:
Fixed:
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:
Create exe_hex directly to avoid allocating exe.
25 21.3 MiB 0.0 MiB 1 exe_name = Path("eldenring.exe") 26 179.0 MiB 0.0 MiB 2 with open(exe_name, "rb") as f: 27 179.0 MiB 157.7 MiB 1 exe_hex = f.read().hex()
Free exe_hex once it's no longer needed.
71 179.0 MiB 0.0 MiB 2 with open(patched_exe_dir / exe_name, "wb") as f: 72 179.0 MiB 0.0 MiB 1 f.write(bytes.fromhex(exe_hex)) 73 74 21.3 MiB -157.7 MiB 1 del exe_hex
The alternative would be to put all the exe stuff inside a function, and exe_hex would get cleaned up when it goes out of scope.
Hey, thanks for the fix! Definitely makes sense to save some memory. I'll merge it right in :)
Hi, thanks for making this script. I was looking at the code, and noticed that
exe
andexe_hex
aren't being freed, so the script hogs a lot of memory while the game is running.Before:
Fixed:
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.
The memory stays in use until the end of the script:
I made two changes:
Create
exe_hex
directly to avoid allocatingexe
.Free
exe_hex
once it's no longer needed.The alternative would be to put all the exe stuff inside a function, and
exe_hex
would get cleaned up when it goes out of scope.