Skip to content

Local-player analysis: build it only for the passes which use it - #1430

Merged
Frotty merged 2 commits into
masterfrom
local-player-analysis-once
Oct 11, 2026
Merged

Frotty merged 2 commits into
masterfrom
local-player-analysis-once

Conversation

@Frotty

@Frotty Frotty commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

The client-local analysis (LocalPlayerContextAnalyzer) is a whole-program analysis. A Lua build of castle fight or zombie defense made it five times. Two of those five were built for passes which never use it: about a third of the analysis time on both maps.

What changes

  • The function splitter runs the copy propagation and the local merger on the compile-time state before splitting it. Both passes ask the analysis only about locals, and a split function has no parameters. The compile-time state of both maps has no locals at all after the flatten (266 and 38,283 elements, 0 locals), so neither pass asked anything. The analysis is now made only when the function has a local, so the output is identical.
  • The old-generics cast temporaries (LuaOldGenericsCasts) went through the local merger with a fresh analysis, right before the Lua translation. The merger keeps a client-local value and a synchronized one in separate locals so that the analysis made before it stays true for the passes which use it afterwards (a merged local would hold both values while the analysis still answers for each). This is the last pass and nothing reads an analysis after it, so it now merges without one. Merging only renames locals, so the program does the same, and a client-local local may share its slot with a dead synchronized one.
  • isLocalPlayerSource is a lookup in a fixed list of natives. It is now static, so the inliner no longer builds the whole analysis to ask it.
  • The merger's barrier now has a comment saying why it is there.

Effect

castle fight Lua zombie defense Lua
analyses made 5 → 3 5 → 3
CPU of all analyses per build (two master runs → change) 3.36 / 2.61 s → 1.89 s 1.42 / 1.47 s → 0.95 s
script identical 3 fewer locals, 344 bytes smaller, same 384,391 instructions (luac)

The zombie defense difference is only merging. Three functions lose one local each; every other function differs only in the numbering of names. Both scripts pass luac -p. The CPU times come from a temporary probe around the constructor (thread CPU time, not committed); a whole build varies more than this from run to run, so no wall time is quoted. Not run in game.

Tests

  • oldGenericsCastMergeIgnoresLocality (new, LuaBackendAuditTests): a function with a client-local integer, a synchronized one and an old-generics cast. It checks that the client-local local is reused for a synchronized value. It fails on master, where the client-local value keeps a third local.
  • clientLocalNativeValuesAreLocalitySources calls the source list directly and no longer builds an analysis around it.
  • Passed (495 tests): LuaBackendAuditTests, OptimizerTests, LocalPlayerContextAnalyzerTests, CompiletimeTests, CompiletimeHashtableTests, CompiletimeNativesTest, LuaTypecastingTests. The full suite is left to CI.

The function splitter's two passes ask it only about locals, which the compile-time state has none of on real maps; the old-generics cast temporaries are merged after the last pass, where nothing reads an analysis any more. A castle fight or zombie defense Lua build makes it three times instead of five.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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-11T07:57:07.413536Z ccfa7c9 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 11, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a4b67c740c

ℹ️ 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 commented Oct 11, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: ccfa7c9795

ℹ️ 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 b27d519 into master Oct 11, 2026
3 checks passed
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