Skip to content

perf(network): Remove extern and add const to global network variables#2726

Open
Caball009 wants to merge 2 commits into
TheSuperHackers:mainfrom
Caball009:refactor_network_globals
Open

perf(network): Remove extern and add const to global network variables#2726
Caball009 wants to merge 2 commits into
TheSuperHackers:mainfrom
Caball009:refactor_network_globals

Conversation

@Caball009
Copy link
Copy Markdown

@Caball009 Caball009 commented May 17, 2026

This PR removes the "-RunAhead" command line so that a couple of global network variables can be marked static const static constexpr const for safety and performance. Considering that the "RunAhead" command is for development only and likely rarely used, I think it's ok to get rid of it.

The current setup with extern in the header and definition in the source file causes the compiler to miss out on optimizations. It's possible that link time optimization would fix this, but that's not currently used.

TODO:

  • Replicate in Generals.

@Caball009 Caball009 added Minor Severity: Minor < Major < Critical < Blocker Performance Is a performance concern Network Anything related to network, servers labels May 17, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 17, 2026

Greptile Summary

This PR converts five network timing globals (MIN_LOGIC_FRAMES, MAX_FRAMES_AHEAD, MIN_RUNAHEAD, FRAME_DATA_LENGTH, FRAMES_TO_KEEP) from extern linkage into static constexpr const definitions in the shared header, and removes the -RunAhead developer command line that was the only runtime mutation point for GeneralsMD.

  • NetworkDefs.h: The five variables are now compile-time constants, enabling inlining and constant-folding optimizations.
  • NetworkUtil.cpp: The corresponding global definitions are deleted.
  • GeneralsMD/CommandLine.cpp: parseRunAhead and the -RunAhead entry are removed cleanly — but the equivalent Generals/Code/GameEngine/Source/Common/CommandLine.cpp is not updated, so it still tries to assign to these now-const symbols and will fail to compile.

Confidence Score: 2/5

Not safe to merge as-is — the shared header change breaks compilation of the Generals code path.

The shared NetworkDefs.h now declares all five network timing constants as static constexpr const, but Generals/Code/GameEngine/Source/Common/CommandLine.cpp still includes that header and directly assigns to those constants inside parseRunAhead. This is a definite compilation failure for the Generals build. The TODO in the PR description acknowledges the gap, but the header change is already present, so the Generals code is broken by this PR in its current state.

Generals/Code/GameEngine/Source/Common/CommandLine.cpp — the parseRunAhead function and -RunAhead command-line entry must be removed (mirroring what was done in GeneralsMD) before this PR can be merged.

Important Files Changed

Filename Overview
Core/GameEngine/Include/GameNetwork/NetworkDefs.h Converts five network timing globals from extern declarations to static constexpr const inline definitions; moves the @tweak comment here from NetworkUtil.cpp
Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp Removes the five global variable definitions that were moved to the header as constexpr constants; no other changes
GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp Removes parseRunAhead function and -RunAhead command-line entry from GeneralsMD correctly, but the equivalent Generals/ file is not updated in this PR, causing a compile error there

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph Before
        A["NetworkUtil.cpp\nglobal Int MIN_RUNAHEAD = 4\nglobal Int MAX_FRAMES_AHEAD = 128\n..."]
        B["NetworkDefs.h\nextern Int MIN_RUNAHEAD\nextern Int MAX_FRAMES_AHEAD\n..."]
        C["CommandLine.cpp (GeneralsMD)\nparseRunAhead:\n  MIN_RUNAHEAD = atoi(args[1])\n  MAX_FRAMES_AHEAD = atoi(args[2])"]
        D["CommandLine.cpp (Generals)\nparseRunAhead:\n  MIN_RUNAHEAD = atoi(args[1])\n  MAX_FRAMES_AHEAD = atoi(args[2])"]
        A --> B
        B --> C
        B --> D
    end
    subgraph After
        E["NetworkDefs.h\nstatic constexpr const Int MIN_RUNAHEAD = 4\nstatic constexpr const Int MAX_FRAMES_AHEAD = 128\n..."]
        F["CommandLine.cpp (GeneralsMD)\n-RunAhead REMOVED ✅"]
        G["CommandLine.cpp (Generals)\nparseRunAhead still assigns\nto const variables ❌ COMPILE ERROR"]
        E --> F
        E --> G
    end
Loading

Reviews (2): Last reviewed commit: "Changed variables to 'static constexpr c..." | Re-trigger Greptile

Comment thread Core/GameEngine/Include/GameNetwork/NetworkDefs.h Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Minor Severity: Minor < Major < Critical < Blocker Network Anything related to network, servers Performance Is a performance concern

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants