[Engine V2] step field on actions#12234
Open
michaeljb wants to merge 4 commits intotobymao:v2-initfrom
Open
Conversation
step field after processing action, use if setstep field after processing action; use the step field if available to choose the Step to process the action
step field after processing action; use the step field if available to choose the Step to process the actionstep field after processing action; use the step field if available to choose the Step to process the action
step field after processing action; use the step field if available to choose the Step to process the actionstep field after processing action; use the step field if available to choose the Step to process the action
step field after processing action; use the step field if available to choose the Step to process the actionstep field after processing action; use the step field if available to choose the Step to process the action
step field after processing action; use the step field if available to choose the Step to process the actionstep field on actions
ollybh
reviewed
Dec 19, 2025
Collaborator
ollybh
left a comment
There was a problem hiding this comment.
This looks like a good change to me, though I've got a suggestion for a tweaked algorithm for calculating the lookup hash for steps.
Comment on lines
+50
to
+64
| if grouped_steps.one? | ||
| step = grouped_steps[0] | ||
| steps_h[step_type] = step | ||
| steps_h[step] = step_type | ||
| else | ||
| grouped_steps.each.with_index do |grouped_step, index| | ||
| key = | ||
| if index.zero? | ||
| step_type | ||
| else | ||
| "#{step_type}#{index + 1}" | ||
| end | ||
| steps_h[key] = grouped_step | ||
| steps_h[grouped_step] = key | ||
| end |
Collaborator
There was a problem hiding this comment.
This seems over-optimised for a block that's going to get called just once a round. Most of the code on both branches of the if statement is repeated.
Suggested change
| if grouped_steps.one? | |
| step = grouped_steps[0] | |
| steps_h[step_type] = step | |
| steps_h[step] = step_type | |
| else | |
| grouped_steps.each.with_index do |grouped_step, index| | |
| key = | |
| if index.zero? | |
| step_type | |
| else | |
| "#{step_type}#{index + 1}" | |
| end | |
| steps_h[key] = grouped_step | |
| steps_h[grouped_step] = key | |
| end | |
| grouped_steps.each_with_index do |grouped_step, index| | |
| key = "#{step_type}#{index.zero? ? '' : index + 1}" | |
| steps_h[key] = grouped_step | |
| steps_h[grouped_step] = key | |
| end |
I've tested this and it's a few milliseconds faster than your code, mostly because each_with_index is more efficient that each.with_index (it doesn't need to create an Iterator). The change in the inner block is basically the same speed.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#12193
This PR depends on #12217.
Before clicking "Create"
masterpinsorarchive_alpha_gameslabel if this change will break existing gamesdocker compose exec rack rubocop -adocker compose exec rack rakeImplementation Notes
Explanation of Change
Action::Basestepattr toActionobjectsRound::BaseAction'sstepstep, use it to quickly select whichStepto use; otherwise, use the old/non-lazy method of checking allSteps in order for one that can process the given action, and throwing an error if a blockingStepthat cannot process the action is foundstepto actionsundoandredoactions have been removedGame'suse_engine_v2is nottrue,stepis not set on any actions, and the wayRoundprocesses actions is unchangedScreenshots
1889 fixture showing faster processing with the
stepfield changes. Legacy on top (viav2=f) processed the actions in 0.379 seconds, and Engine V2 (v2=t) on the bottom took 0.263 seconds:The above screenshot is one of many trial results:
Any Assumptions / Hacks
TODOcomment has been added to address this, and a checklist item has been added to #12193.