[DEPRECATED] How-to: decreasing UI memory usage on Windows / Linux

Discussion in 'Support!' started by SXX, August 19, 2014.

  1. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    Warning! This is no longer required since PTE build 72908 that implemented limit for renderer process limit (4 by default) and also give you possibility to pass arbitrary options to Coherent Host via PA executable command line switches.
    https://forums.uberent.com/threads/pte-stream-72908.64565/


    If you want to set renderer process limit now please use this option for PA executable:
    Code:
    --coherent-options="--renderer-process-limit=2"
    Last edited: October 9, 2014
  2. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    I think the only difference for OS X vs. Linux is that the "directory where the game is installed" is PA.app, which by default doesn't appear as a directory. You have to "Show Package Contents", and then to go to Contents/MacOS/host.

    Also, save a copy of the script, because the updater will probably "fix" things every time there is an update. I know I have to re-copy devtools every time.
  3. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    Thanks. If you can PM me some step-by-step how-to I'll add it into the topic.

    Also can you please check memory usage difference? :rolleyes: (in MB)
    As far as I get Coherent is 64-bit on Mac so it's should be as big as on Linux...
    Last edited: August 19, 2014
  4. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    Ooops, just find out that I lost "Windows Registry Editor Version 5.00" part of ".reg" file in original post... :(
    Fixed now!
  5. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    So other interesting result on Windows 8.1 virtual machine.

    I just tested PA with only one UI renderer process and "--software-ui" flag. In-game it's only used 230MB RAM!
  6. Shwyx

    Shwyx Well-Known Member

    Messages:
    270
    Likes Received:
    287
    I have 8 GB of RAM but an otherwise weak machine, especially my GPU and its VRAM. Would this change net me any noticeable performance gains?
    spittoon likes this.
  7. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    It's not likely that number of renderer processes affect GPU or VRAM usage because even if they're call "renderer" it's doesn't mean they use GPU. Chromium/Coherent only have one process that's access GPU and it's likely use 150-250MB of VRAM for UI rendering.

    You can disable UI GPU acceleration using standard "--software-ui" flag for PA. ;)
  8. thetrophysystem

    thetrophysystem Post Master General

    Messages:
    7,050
    Likes Received:
    2,874
    This was a great discovery both as an advance touchup and troubleshoot, and as a game feature of high value.


    in light of this, I never cared about dox balance much, but this would be sooo much better.
  9. thetrophysystem

    thetrophysystem Post Master General

    Messages:
    7,050
    Likes Received:
    2,874
    Test1: Just ran, and something I must have fudged up, because PA errors on attempt to start: "fatal error: unexpected error attempting to initialize coherent ui subsystem. please contact support@uberent.com"

    I obviously won't contact them because I am the one that fudged it up. I will attempt to troubleshoot my registry now, probably the complex install directory I used...

    Test2: Edited registry manually via the path in the code. Somehow recopying it fixed it, probably WAS the complexity of the path, kids at home: It helps to install PA to a simple directory immediately in your drive and not through complex folders and names and such.

    NOW it runs, so... I specified 9 and it spawns 8 processes? What's going on there?

    270k of ram? That isn't a lot I think. Am I missing a hidden coherent process you think?

    Game runs well. Wierd side effect: Game takes longer to generate planets. Last update, it took almost 30 seconds or more to generate planet even after generated in lobby before game rendered. This update, unmodded it goes instantly. With this tweak, it takes about 8 seconds, comes up just a little while.
    Last edited: August 21, 2014
  10. exterminans

    exterminans Post Master General

    Messages:
    1,881
    Likes Received:
    986
    Tested with the same planet? Planets with many trees are well known to take much longer to generate.
  11. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    Before you're in-game (after game loaded) there is less than 10 Coherent views so really few processes. Once you in-game it's spawn 32 renderer processes by default so as result there is 33-34 in total and with this flags this number have to be decreased.

    Are you running on Linux or Windows? Do you using "--software-ui" or not?

    I suppose it's excepted especially on slow CPU/GPU, but it's a lot better than being out of RAM. :)
  12. a2razor

    a2razor Member

    Messages:
    32
    Likes Received:
    24
    Since doing as described here does cause issues with some other games, yet helps tremendously with one of my lower memory systems (8GB ram). I've taken the liberty of writing a bit beefier script for Windows machines and automating both doing it and undoing it.

    Feel free to use this if you guys want, especially so you don't interfere with the launcher during verify & update process.


    Just copy paste the contents into a batch file, and follow the comments for setting a path.
    Code:
    @echo off
    :: BatchGotAdmin
    :-------------------------------------
    REM  --> Check for permissions
    >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
    
    REM --> If error flag set, we do not have admin.
    if '%errorlevel%' NEQ '0' (
        echo Requesting administrative privileges...
        goto UACPrompt
    ) else ( goto gotAdmin )
    
    :UACPrompt
        echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
        set params = %*:"=""
        echo UAC.ShellExecute "%~s0", "%params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
    
        "%temp%\getadmin.vbs"
        exit /B
    
    :gotAdmin
        if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
        pushd "%CD%"
        CD /D "%~dp0"
    :--------------------------------------
    
    :--------------------------------------
    REM --> Remember to update path to CoherentUI here!
    set src=C:\Win8\Games\Uber Entertainment\Planetary Annihilation Launcher\Planetary Annihilation\stable\bin_x64\host
    set num_instances=5
    :--------------------------------------
    
    :JMP_MENU
    CLS
    ECHO 1 - Restore
    ECHO 2 - Limit CoherentUI
    
    SET /P M=Type 1 or 2 then press ENTER:
    IF %M%==1 GOTO JMP_RESTORE
    IF %M%==2 GOTO JMP_MODIFY
    GOTO JMP_MENU
    
    :JMP_RESTORE
    reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\CoherentUI_Host.exe" /v Debugger /f
    del "%src%\CoherentUI_Real.exe"
    GOTO JMP_END
    
    :JMP_MODIFY
    reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\CoherentUI_Host.exe" /v Debugger /t reg_sz /d "%src%\CoherentUI_Real.exe --renderer-process-limit=%num_instances%" /f
    del "%src%\CoherentUI_Real.exe"
    mklink "%src%\CoherentUI_Real.exe" "%src%\CoherentUI_Host.exe"
    GOTO JMP_END
    
    :JMP_END
    ECHO.
    ECHO.
    ECHO.
    ECHO Done...
    pause
    -Note that a symlink is used so that executable name of the running process isn't altered. This prevents interference with GPU utilities and executable name match.
    Last edited: August 22, 2014
  13. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    I suppose workaround for this would be changing CoherentUI_Host.exe name to something unique for PA, but it's does looks like Coherent dll PA using is digitally signed on Windows and it's not going to work when patched. :(
  14. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    Also you looks like someone familiar with Windows specifics. Might be you can have any idea why would usage of my exe wrapper cause inability to display UI rendering results?
    https://forums.uberent.com/threads/creating-wrapper-for-coherent-on-windows-need-help.63037/

    This my wrapper should properly connect pipes and everything work with it except actual UI bitmaps display while IFEO trick don't cause any issues. On Linux Coherent using shared memory to transfer rendered bitmaps and just passing correct UUID works, so why this not work on Windows? :(
  15. zweistein000

    zweistein000 Post Master General

    Messages:
    1,362
    Likes Received:
    727
    So this reduces UI memory usage, but it also reduces responsiveness and increases the UI load time?

    It's good, but not what I want since the UI load time is epic as it is.
  16. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    It's does increase load time, but not dramatically. Responsiveness might be a bit lower, but it's a lot better than being out of RAM.

    If it's take too long for you try to adjust it slowly, e.g not 5 renderers, but 10 or 12 for example.

    PS: By default it's 32 renderers each eating 30MB RAM as minimum and most of these views don't actually need separate process to work fast. So you can find point where RAM usage decreased without any loss sure.
  17. a2razor

    a2razor Member

    Messages:
    32
    Likes Received:
    24

    It probably uses some form of shared mem on Windows as well, as realistically speaking (in Windows) your options are:
    -Memory Mapped File
    -Shared Memory Pipe
    -Shared Memory region of a DLL loaded by two processes (doesn't permit user-permissions and isn't secure, so people generally avoid it) >> this is the old-approach
    -Some combination of the above w/ using mutexes for process serialization
    -Windows Messaging (PostMessage, SendMessage: to a window handle)
    -Using network streams connected to loopback (eg, use UDP / TCP)


    The only thing you're really changing by shoving another executable in the middle, is the PID seen by the launching process. While I can think of many ways that this might screw up termination, or monitoring if the other process is active ... I can't think directly of how it'd screw up the memory based IPC between them.

    In the case of to window message passing, that might get broken if one end uses EnumWindows to scan through active window handles, and then match them to the PID of the launched process. But, this is pretty rare and usually the calling process launches the other and just passes a handle (rather than having the other search for its window). It's also far easier to just use Shared Memory too. Yet, really I have no idea how CoherentUI works as a whole.

    I'd have to take a look at it and see how CoherentUI is started and interacts in both cases, imo.


    -On quick inspection, it seems that PA uses CreateProcessW to launch CoherentUI. Another option rather than having as you called it a "proxy or wrapper", would be to simply code up a launcher for PA.exe that starts the process suspended, and trampolines / hooks that function (via IAT patching, so that we can alter the parameters sent to it).

    ^ Yet this would be a bit invasive, and probably cause issues depending the type of software protection used.



    Ideally we should appeal to get this made a changeable parameter within PA itself.
  18. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    Thank you for interesting post. I'll have to check few other ideas now... :)

    Actually it's other thing I can't find information about. On Linux you can use "exec" syscall that let you wrap separate process without PID changing (as far as I get) because it's replace process image instead of forking it.

    PA don't use any protectors for sure, but as far as I get game can't directly say what flags passed to "UI host".

    Obviously I reported about my findings to developers first and they was positive about including some options to control UI renderers limit. Though as far as I get this will require some cooperation from Coherent developers.
    Last edited: August 24, 2014
  19. admrialmardok

    admrialmardok New Member

    Messages:
    10
    Likes Received:
    2
    Could I get a little help with this?
    i cant find the CoherentUI.exe file in my registry, and the .reg file i made says its not a reg file when i run it.
    i did get the game through steam, will this cause any issues with the fix? i'm also running a 32 bit system(x86 instead of x64)
  20. SXX

    SXX Post Master General

    Messages:
    6,896
    Likes Received:
    1,812
    You won't find it in registry until you create file on your own.

    If you pack your .reg file into ZIP and upload here then I'll try to find out why it's don't want to import it. Likely you just put some invalid symbol here.

    It's doesn't mater because CoherentUI_Host.exe on Windows is 32-bit only.

Share This Page