Skip to content

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

Open
Caball009 wants to merge 4 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 4 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 promotes five previously extern-linked mutable network globals (MIN_LOGIC_FRAMES, MAX_FRAMES_AHEAD, MIN_RUNAHEAD, FRAME_DATA_LENGTH, FRAMES_TO_KEEP) to static constexpr const in the shared header, and converts the remaining static const declarations in NetworkDefs.h to static constexpr const as well. To make this possible, the development-only -RunAhead command-line option — which modified those values at runtime — is removed from both the Generals and Zero Hour game variants.

  • NetworkDefs.h: extern Int declarations replaced with inline static constexpr const definitions; derived values (FRAME_DATA_LENGTH, FRAMES_TO_KEEP) are now computed as constant expressions from MAX_FRAMES_AHEAD.
  • NetworkUtil.cpp: Five global variable definitions deleted; file is otherwise unchanged.
  • CommandLine.cpp (both variants): parseRunAhead() function and the -RunAhead parameter entry removed in sync, resolving the PR's own TODO.

Confidence Score: 5/5

Safe to merge — the change is a straightforward constexpr promotion with no functional impact on normal gameplay paths.

The formerly mutable globals are now compile-time constants whose values are identical to the previous runtime defaults. The only removed capability is the developer-only -RunAhead flag, which is acknowledged and intentional. Both game variants are updated consistently.

No files require special attention.

Important Files Changed

Filename Overview
Core/GameEngine/Include/GameNetwork/NetworkDefs.h Converts extern mutable globals and static const to static constexpr const, inlining values for compiler optimization. A relocated comment carries a 2025 date.
Core/GameEngine/Source/GameNetwork/NetworkUtil.cpp Removes the now-redundant global variable definitions for MIN_LOGIC_FRAMES, MAX_FRAMES_AHEAD, MIN_RUNAHEAD, FRAME_DATA_LENGTH, and FRAMES_TO_KEEP, which are now constexpr in the header.
Generals/Code/GameEngine/Source/Common/CommandLine.cpp Removes parseRunAhead function and the -RunAhead command-line parameter registration, consistent with the variables becoming compile-time constants.
GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp Same -RunAhead removal as Generals/; both game variants are updated in sync, addressing the PR TODO.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["NetworkDefs.h\nstatic constexpr const\nMIN_LOGIC_FRAMES = 5\nMAX_FRAMES_AHEAD = 128\nMIN_RUNAHEAD = 4\nFRAME_DATA_LENGTH = (128+1)*2\nFRAMES_TO_KEEP = (128/2)+1"] -->|included by| B["NetworkUtil.cpp\n(definitions removed)"]
    A -->|included by| C["Other TUs\n(values inlined at compile time)"]
    D["CommandLine.cpp\n(Generals + Zero Hour)"] -->|removed| E["-RunAhead handler\nparseRunAhead()"]
    E -.->|"previously mutated (now const)"| A
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
Core/GameEngine/Include/GameNetwork/NetworkDefs.h:35-36
This comment was newly added to the header file and references a date from 2025, which is prior to the current year (2026). Per project convention, newly created comments should use the current year.

```suggestion
// TheSuperHackers @tweak Mauller 26/05/2026 reduce the minimum runahead from 10
// This lets network games run at latencies down to 133ms when the network conditions allow
```

Reviews (3): Last reviewed commit: "Replicated in Generals." | Re-trigger Greptile

Comment thread Core/GameEngine/Include/GameNetwork/NetworkDefs.h Outdated
Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok

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.

3 participants