Repository navigation
Build the global layout once per compiled expression or program - #684
bertysentry wants to merge 2 commits into
Conversation
The names-by-offset list and the offsets-by-name map of the globals were rebuilt by RuntimeStack on every eval() and execute(), from the same offset map as the previous run. They are now built once per compiled AwkExpression/AwkProgram, as an immutable GlobalVariableLayout that every AVM shares, and the runtime stack keeps its (cleared) globals array when the next run uses the same layout. Every plain run still starts with uninitialized globals, and the persistent-globals path, which binds a merged layout by name, is unchanged. Fixes #678 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012oN698mGzDdiNqivAHYLdk
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5a8cb1ab6c
ℹ️ 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".
| * every runtime that executes it, on any thread. | ||
| * </p> | ||
| */ | ||
| public final class GlobalVariableLayout { |
There was a problem hiding this comment.
Document or hide the new global-layout API
This commit exposes GlobalVariableLayout, its factory and accessors, and the inherited public AwkTuples.getGlobalVariableLayout method without updating either the site documentation or README. Either keep this implementation detail out of the public surface or document its supported contract in the required user-facing documentation.
AGENTS.md reference: AGENTS.md:L35-L37
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Traced this: the type cannot be hidden, because the cache lives on io.jawk.intermediate.AwkTuples and is consumed by io.jawk.backend.RuntimeStack/AVM (two packages, Java 8, no modules). It sits next to getGlobalVariableOffsetMap() / getGlobalVariableAarrayMap(), and nothing of io.jawk.intermediate is described in src/site or the README today, which document the embedding API (Awk, AwkProgram, AwkExpression, AVM, CLI). So rather than advertise interpreter plumbing as a supported contract, 42f7ff5 states in the Javadoc of GlobalVariableLayout and AwkTuples.getGlobalVariableLayout that they are runtime plumbing, not an API for embedders. Leaving this thread open for @bertysentry to decide whether a site-doc entry is wanted anyway.
Generated by Claude Code
…Support - Build the global layout when the compiled metadata is frozen (and again on deserialization) instead of lazily, so every runtime gets the same instance without any race. - Run the new AWK-script tests through AwkTestSupport, extended with runsOnSharedRuntime(...) to chain evaluations, executions and persistent executions on one reused runtime. - State in the Javadoc that the global-layout types are runtime plumbing, not an API for embedders. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012oN698mGzDdiNqivAHYLdk
|
@codex please review again Generated by Claude Code |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Fixes #678
Problem
Every
eval()/execute()on a reusedAVMrebuilt the global layout inRuntimeStack.setGlobalLayoutMetadata: a newObject[], anArrayListof names (copied twice) and aLinkedHashMapof offsets, all from the same offset map as the previous run of the same expression.Change
GlobalVariableLayout(new,io.jawk.intermediate): immutable names-by-offset list + offsets-by-name map. Runtime plumbing between the tuple stream and the interpreter, not an API for embedders (stated in its Javadoc).AwkTuples: builds the layout once infreezeMetadata(), before the compiled program/expression is exposed, so every AVM on every thread gets the same instance with nothing lazy to race on. The field istransient;readObjectrebuilds it for a deserialized program.getGlobalVariableLayout(int numGlobals)returns it.RuntimeStack:setNumGlobals(layout)binds the shared layout instead of building one.clearGlobals()clears the slots of a compiled-layout array (Arrays.fill(globals, null)) and keeps it; the nextsetNumGlobalsreuses it when it gets the same layout instance, and allocates otherwise.AVM: remembers the installed compiled tuples (installedTuples) and asks them for the layout inexecSetNumGlobals.The persistent-globals path is not changed:
rebindGlobals(List<String>)still builds its own merged by-name layout, and such arrays are never reused or cleared.Nothing visible changes: every plain run still starts with uninitialized globals. No
behavior-changes.mdentry (pure performance change).Tests
AwkTestSupportgainsrunsOnSharedRuntime(...)withevalRun/evalAgainRun/executeRun/persistentRunsteps, to chain evaluations, executions and persistent executions on one reused runtime.GlobalLayoutReuseTest(all throughAwkTestSupport): repeated eval of the same expression (scalars and arrays), eval continuing on the same eval state, alternating two expressions, execute after eval and eval after execute, repeated execute, pre-assigned globals re-applied on each run, persistent execution still carrying globals, eval after persistent executions.RuntimeStackTest(plain JUnit): layout binding, array reuse for the same layout instance, new array for another layout, rebound (merged) globals never reused.GlobalVariableLayoutTest(plain JUnit): layout construction, read-only views, one instance per compiled expression/program including concurrent first uses, no caching before the metadata is frozen, rebuild after a serialization round trip.mvn verifyis green locally (unit tests, checkstyle, PMD, SpotBugs, license headers, Javadoc); the compatibility-suite results are identical tomain.Note for the sibling PRs
AVM.javachanges are limited to one field, one line in each ofresetTransientRuntimeState/installExpressionMetadata/installProgramMetadata, and thesetNumGlobalscall inexecSetNumGlobals.AwkTestSupportonly gets additions.🤖 Generated with Claude Code
https://claude.ai/code/session_012oN698mGzDdiNqivAHYLdk