Skip to content

Propagate copies of values which depend on the local player - #1482

Merged
Frotty merged 2 commits into
masterfrom
ccp-local-player-copies
Oct 17, 2026
Merged

Frotty merged 2 commits into
masterfrom
ccp-local-player-copies

Conversation

@Frotty

@Frotty Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member

Constant and copy propagation refused every value the local-player analysis marks as dependent. The guard came with #1207 as "deliberately conservative", without a test of its own.

Why it is safe to drop

A propagation replaces a read of a local by the local or constant it is known to hold at that point (q = voter; f(q) becomes f(voter)). Sources are locals, constants and call results only; a global is never a propagation source. On every client the replaced read sees the value the original read saw, and no computation moves, appears or disappears. So the transformation preserves each client's behaviour exactly and cannot make clients diverge, whatever the value depends on. The passes which do move code keep their locality checks: the local merger (now the only locality-aware pass in the sweep) and the branch merger's hoisting.

Without the guard the pass needs no locality analysis, so it is an ordinary OptimizerPass. FunctionSplitter now builds the analysis for the local merger only, after the propagation (before, the merger was asked about a body the propagation had already rewritten). The analyzer's doc no longer lists the propagation among the passes which move code.

Why it matters

In UI code most values derive from client-local frame state, so the analysis marks whole functions dependent and the guard kept almost every copy the inliner makes. On the optimised Lua of two large maps (static luac 5.3 instructions):

before after
map A instructions 497,819 482,726 (-3.0%)
map A script size 8.98 MB 8.53 MB
map A local-to-local copies 17,024 4,052
map B instructions 318,761 308,796 (-3.1%)
map B script size 5.64 MB 5.35 MB
map B local-to-local copies 11,811 3,220

Most of it is MOVE (-13,090 and -8,610). With the aliases gone, the redundant-field-store pass also sees more duplicate field initialisations. For example, ArrayList_size_storage[this] = 0 after ArrayList:create() had already written 0 through another alias. That removes 535 and 219 table writes.

Tests

  • OptimizerTests.copyOfLocalPlayerValueIsPropagated: a local copied from a field holding GetLocalPlayer(), with the source still live (so the merger cannot remove it). On master the optimised Jass keeps local player q = voter; now every read uses voter.
  • Run locally (Windows): OptimizerTests (including all local-player tests), LocalPlayerContextAnalyzerTests, LuaBackendAuditTests, LuaTranslationTests, ObservableEffectsTests, DeterministicChecks, CompiletimeTests and the Lua backend classes, 739 tests.

This is independent of #1481 (the other copy-propagation fix), which touches a different part of the same file.

Constant and copy propagation refused every value the local-player
analysis marks as dependent, "deliberately conservative" since #1207. A
propagation replaces a read of a local by the local or constant it is known
to hold at that point: on every client the replaced read sees the value the
original read saw, and no computation moves, appears or disappears, so it
cannot make clients diverge. The passes which do move code (the local merger,
the branch merger) keep their locality checks.

In UI code, where most values derive from client-local frame state, the
guard kept almost every copy the inliner makes. Without it the pass needs no
locality analysis and is an ordinary pass; the function splitter builds the
analysis for the local merger only, after the propagation.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T16:17:14.801957Z 8fe7bf8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Frotty

Frotty commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 8fe7bf8e41

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty
Frotty merged commit 192884e into master Oct 17, 2026
2 checks passed
@Frotty
Frotty deleted the ccp-local-player-copies branch November 25, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant